Python learning 2 --- string, python --- string
I. String
1.1. String and escape characters
Escape characters must be expressed \.
1.2 string connection
Print string 1 string 2, printed strings are directly connected together without spaces
Print string 1, string 2, printed strings are directly connected together with spaces
You can also use the variable Assignment Method to output a string, and use the plus sign to connect the variables together. The result is the same as above.
1.3, str () and repr ()
Str () converts a value to a string
Repr () Return Value string representation, only return value, not conversion
Ii. input and raw_input ()
Input (): The input value is a value assignment operation by default. Only numbers or "content" can be entered. manually add quotation marks.
Raw_input (): the default input is a string.
Use raw_input () whenever possible ()
Differences
3. original string and Unicode string
If r is added before the string, All characters in the string are not escaped, including escape characters.
Unicode is preceded by a string, and unicode is only a character encoding.
In python, common strings are stored internally in the form of 8-bit ASCII code, while UNICODE strings are 16-bit Unicode characters, which can represent more character sets.
Iv. functions used
Abs (number): returns the absolute value of a number. For example, abs (-3) = 3;
Cmatch. sqrt (number): returns the square root or a negative number.
Float (object): converts strings and numbers to floating point float (3) = 3.0
Help (): provides interactive help
Input ("prompt information"): obtains user input, but can only enter numbers. If you want to enter characters, manually add double quotation marks
Int (object): converts a string or number to an integer int (3.2) = 3; int (3.9) = 3; int (-3.2) =-3; int (-3.9) =-3; remove decimal places, only the integer
Long (object): converts a string or number to a long integer. long (3) = 3L. If there is a decimal point, remove the decimal point and only take the integer. The negative number is the same.
Math. ceil (number): the upper integer of the returned number. The type of the near return value is a floating point number, for example, math. ceil (12.1) = 13.0, math. ceil (-12.1) =-12.0, math. ceil (-12.9) =-12.0,
Math. floor (number): bottom-in integer of the returned number. The type of the near-return value is a floating-point number, for example, math. floor (12.9) = 12.0, math. floor (-12.1) =-13.0, math. floor (-12.9) =-13.0
Math. sqrt (number): near returns the square root. If it is not suitable, It is negative. math. sqrt (4) = 2.0.
Pow (x, y): x indicates the base number, y indicates the power number, and returns x to the Power y. pow (0.25) = 4, pow (2,-2) =.
Raw_input ("prompt message"): gets user input. The return value type is string.
Repr (object): String Representation of the returned value. It is only a form and is not converted.
Round (x, y): returns x rounded to the given precision of the root, which is the number of operations and y is the precision.
Round (11.5) = 12, round (-11.5) =-11,
Round (14.5,-1) = 10, round (-14.5,-1) =-20,
Round (16.5,-1) = 20, round (-16.5,-1) =-20,
Round (56.5,-2) = 100, round (-56.5,-2) =-100
Str (object): converts a value to a string.