Variable usage considerations
- Use the lowercase l and the capital Letter o sparingly, as they may be seen as values 1 and 0.
- The lowercase python variable name should be used.
String
In Python, a string is enclosed in quotation marks, where the quotation marks can be single quotes and double quotes.
"This was a string" ' This is also a string '
Capitalize the initial letter
Using the title method to achieve
1 " Aaron " 2 Print (Name.title ())
titleThe string becomes lowercase
Use the lower method to achieve. When storing data, there are times when you can't rely on users to provide the correct case, so you need to convert the strings to lowercase before storing them.
" Aaron " Print (Name.lower)
LowerString to uppercase
Use the upper method to achieve.
" Arron " Print (Name.upper ())
UpperMerging strings
Python uses a plus sign (+) to combine strings.
1 " Aaron " 2 " Jim " 3 full_name = first_name+""+last_name
string Merge
The string in Python is represented in the C language as a character array, and each time a string is created, it needs to open a contiguous space in memory, and once you need to modify the string, you need to make room again, and the Evil + sign will re-open up a space within each occurrence.
Add blank
Use the tab (\ t) and line break (\ n) to add whitespace.
1 Print ("\tptyhon") 2 Print ("\npython")
View CodeRemove Blank
- Use the Rstrip method to temporarily remove trailing blanks.
1 " "2print(Value.rstrip ())
Rstrip
- Saves the deleted result to a variable, implementing a permanently deleted string trailing whitespace
1 " "2 value_tmp = value.lstrip ()3print(value_tmp)
variable Substitution
Use the Rstrip method to achieve.
1 " python " 2 Print (Value.rstrip ())
Rstrip
Use the Strip method to achieve.
1 " "2print(Value.strip)
Strip
integer int (integral type) on a 32-bit machine, the number of digits of the integer is 32 bits, the value range is -2**31~2**31-1, that is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits, the range is -2**63~2**63-1, that is, -9223372036854775808~9223372036854775807 long (long) is different from the C language, Python's long Integer does not refer to the positioning width, i.e. python does not limit the size of long integer values, but in fact, because of the limited machine memory, we use a long integer value can not be infinite.
Note that, since Python2.2, Python automatically converts integer data to long integers if an integer overflows, so it does not cause any serious consequences if you do not add the letter L after long integer data.
Floating point number
First Literacy http://www.cnblogs.com/alex3714/articles/5895848.html
A floating-point number is used to process real numbers, which are numbers with decimals. Similar to the double type in C, accounting for 8 bytes (64 bits), where 52 bits represent the bottom, 11 bits represent the exponent, and the remaining one represents the symbol. Complex (plural) complex numbers are composed of real and imaginary parts, the general form is X+yj, where x is the real part of the complex number, and Y is the imaginary part of the plural, where x and y are real numbers. Note: Small number pools exist in Python:-5 ~ 257 Boolean true or False 1 or 0
Simple data types of Python data types