Python3 basic data type, Python3 Data Type
Variables in Pyhon do not need to be declared. You only need to assign values before use, and the variables are created after being assigned values.
Python variables do not have a type. The type referred to is only the type of objects in the memory.
Python has six standard data types:
- Numbers (number)
- String (String)
- List)
- Tuple (tuples)
- Sets)
- Dictionaries (dictionary)
Numbers (number)
Python 3 supports int, float, bool, and complex (plural) types. It is very intuitive to use, just like writing an article. The use of numbers can be used as calculators, such:
>>> 5 + 4 # Add 9 >>> 4.3-2 # subtract 2.3 >>>> 3*7 # multiply by 21 >>> 2/4 # Except 0.5 >>> 2 // 4 # integer 0 after Division
Note:
- 1. Python can assign values to multiple variables at the same time, such as a, B = 1, 2.
- 2. A variable can point to different types of objects by assigning values.
- 3. Division (/) always returns a floating point number. To obtain an integer, use the // operator.
- 4. In hybrid computing, Pyhton converts an integer to a floating point number.
String (String)
String 'str' in Python is enclosed by single quotation marks ('') or double quotation marks (" "), and special characters are escaped using a backslash.
>>> S = 'Yes I don \ '# Escape >>> print (s, type (s )) yes I don't <class 'str' >>> print (s, type (s), len (s) Yes I don't <class 'str'> 11
If you want to escape the backslash, you can add an r to the front of the string to indicate the original string. The backslash can be used as a line break to indicate that the previous line is the continuation of the next line.
>>> print('c:\python\bin\local')c:\pythoin\local>>> print(r'c:\python\bin\local')c:\python\bin\local
Strings can be connected in series using the + operator, or the * operator is used to repeat:
>>> book = 'python' + 'C++' + 'Perl'>>> print(book)pythonC++Perl>>> s = 'good'*3>>> print(s)goodgoodgood