Python beginners (2)
V. Variables and assignments
When declaring a variable in Python, you do not need to specify its type. It is automatically determined based on your value assignment.
For values such as numbers and characters, variables only reference them and cannot directly delete their values. (In fact, due to the garbage collection mechanism in Python, you cannot really delete anything, python automatically determines if it is "nobody" before deleting it)
>>> a = 1>>> b = a>>> print(a, b)1 1>>> a = 9>>> print(a, b)9 1
6. Numbers
Int: signed integer (if the range is exceeded, it is automatically converted to a long integer)
Long: A long integer (its range depends on the user's virtual memory)
Float: Floating Point Number
Complex: plural (the imaginary number is represented by a letter j at the end of the number)
Bool: Boolean value (1 indicates True, 0 indicates False, and True + False indicates 1)
VII. String
A string can be defined by a pair of single, double, or triple quotes;
A string is a character sequence. You can use the list slicing operation to obtain the substring of a string. You can also use the subscript index to obtain the position of the character in the string. The subscript of the first character is 0, the subscript of the last character is (-1 );
You can use "+" to connect two strings (a new space will be created in the memory and a new string will be created to represent the connection result ), you can use "*" to specify the number of string repetitions.
>>> py = 'Python'>>> py[-1],py[0]('n', 'P')>>> py[1:-2], py[:], py[2:], py[:3]('yth', 'Python', 'thon', 'Pyt')>>> he = 'Hello'>>> he+py'HelloPython'>>> py*3'PythonPythonPython'