1, null (None)
Indicates that the value is an empty object, and the null value is a special value in Python, represented by none. None is not understood to be 0, because 0 is meaningful, and none is a special null value.
2. Boolean Type (Boolean)
In Python, none, 0 in any numeric type, empty string "", Empty tuple (), empty list [], empty dictionary {} are treated as false, and custom types, and if the __nonzero__ () or __len__ () method is implemented and the method returns 0 or FALSE, The instance is also treated as false and the other objects are true
The Boolean value and Boolean algebra represent exactly the same, a Boolean value of True, false two, or true, or false, in Python, you can directly use True, False to represent a Boolean value (note case), or you can calculate it by Boolean operation:
Copy Code code as follows:
>>> True
True
>>> False
False
>>> 3 > 2
True
>>> 3 > 5
False
Boolean values can also be operations with and, or, and not.
1. And operations are with operations, only the result of all True,and operations is true:
Copy Code code as follows:
>>> true and True
True
>>> True and False
False
>>> false with False
False
2. Or operation is or operation, as long as one of the True,or operations result is true:
Copy Code code as follows:
>>> true or True
True
>>> True or False
True
>>> false or False
False
3. The not operation is a single order operator, which turns true to False,false to true:
Copy Code code as follows:
>>> not True
False
>>> not False
True
4. Boolean values are often used in conditional judgments, such as:
Copy Code code as follows:
If age >= 18:
print ' adult '
Else
print ' teenager '
3, Integral type (INT)
Within Python, the processing of integers is divided into ordinary integers and long integers, the normal integer length is machine bit long, usually 32 bits, and integers exceeding this range are automatically treated as long integers, while the range of long integers is almost completely unrestricted.
Python can handle integers of any size, including, of course, negative integers, which are represented in the program in exactly the same way as mathematically, for example: 1,100,-8080,0, and so on.
4, float type (float)
The floating-point number of Python is the decimal in mathematics, similar to the double in C language.
In operations, the result of integers and floating-point numbers is floating-point numbers
A floating-point number is a decimal, known as a float, because the decimal point position of a float is variable in the scientific notation, for example, 1.23x109 and 12.3x108 are equal. Floating point numbers can be written mathematically, such as 1.23,3.14,-9.01, and so on. But for very large or very small floating-point numbers, we must use the scientific notation, the 10 with e substitution, 1.23x109 is 1.23e9, or 12.3e8,0.000012 can be written as 1.2e-5, and so on.
The way integers and floating-point numbers are stored inside the computer is different, and the integer operation is always accurate (is division also accurate?). Yes! , and floating-point operations may have rounding errors.
5, Strings (string)
Python strings can be enclosed in single quotes or in double quotes, and can even be enclosed in triple quotes
strings are any text enclosed in ' or ', such as ' abc ', ' XYZ ', and so on. Note that the ' or ' itself is only a representation, not part of a string, so the string ' abc ' has only a,b,c these 3 characters. If ' itself is also a character, it can be surrounded by ", such as" I ' m OK "contains the characters I, ', M, space, o,k these 6 characters.
What if the inside of the string contains both ' and contains '? You can use the escape character \ To identify, for example:
Copy Code code as follows:
The string content represented is:
Copy Code code as follows:
Escape character \ Can escape a lot of characters, such as \ n means line break, \ t for tab, character \ itself to escape, so the character is \, can be used in the Python interactive command line print a string to see:
Copy Code code as follows:
>>> print ' i\ ' m OK. '
I ' m OK.
>>> print ' I\ ' m learning\npython. '
I ' m learning
Python.
>>> print ' \\\n\\ '
\
\
If there are many characters in the string that need to be escaped, you need to add a lot of \, in order to simplify, Python also allows the use of the "R" "internal" string default does not escape, you can try:
Copy Code code as follows:
>>> print ' \\\t\\ '
\ \
>>> print R ' \\\t\\ '
\\\t\\
If there's a lot of line wrapping inside the string, it's hard to read in a row, and for simplicity, Python allows you to use the format of ' ... ' to represent multiple lines of content, and try it yourself:
Copy Code code as follows:
>>> print ' line1
... line2
... line3 '
Line1
Line2
Line3
The above is entered in the interactive command line, if written as a program, that is:
Copy Code code as follows:
print ' ' line1
Line2
Line3 ' "
Multi-line string ' ... ' can also be used in front with R, please test yourself.
6, listing (list)
The list is represented by a symbol [], and the middle element can be of any type, separated by commas. List is similar to the array in C language for sequential storage structure
Built-in functions:
Copy Code code as follows:
Append (x) appended to the end of the chain
Extend (L) append a list, equivalent to + =
Insert (I,X) inserts x at position I, the remaining elements are pushed backwards, if I is greater than the list length, it is added at the end, if I is less than 0, it is added at the beginning
Remove (x) deletes the element with the first value x, and throws an exception if it does not exist
Reverse () Reverse sequence
Pop ([i]) returns and deletes the element with position I, and I defaults to the last element
Index (x) returns the first occurrence of x in the list and throws an exception if it does not exist
COUNT (x) returns the number of times X appears
Sort () sorting
Len (list) returns the length of the list
Del List[i] Delete the i+1 variable specified in list
Slice
A slice refers to a part of an extract sequence in the form of: List[start:end:step]. Its extraction rule is: The general default step size is 1, but it can also be customized.
7. Tuple (Yuan Group)
A tuple is a data structure similar to a list, but it cannot be changed once it is initialized, faster than the list, and tuple does not provide dynamic memory management functionality, you need to understand the rules:
Tuple can return an element or a child tuple with the subscript
The method for tuple that contains only one element is: (d,) followed by a comma to distinguish it from a separate variable
8, set (set)
A set is an unordered, repetitive set of elements, similar to a set in mathematics, for logical operations and arithmetic operations.
9. Dictionary (Dict)
A dictionary is an unordered storage structure that includes a keyword (key) and a value (value) corresponding to a keyword. The format of the dictionary is: dictionary = {Key:value}. Keywords are immutable types, such as strings, integers, tuples containing only immutable objects, and lists cannot be keywords. If a keyword pair exists in the list, you can construct the dictionary directly with Dict ()