Basic Python data types
Unlike the C or Java programming languages, variables in Python do not need to be declared, but each variable must be assigned a value before it can be used, and then the variable can be created.
In Python, a variable is a variable, it has no type, and by type we mean the type of the in-memory object to which the variable refers.
There are six standard data types in Python3, as follows:
- Number = Number
- String (String)
- List (List)
- Tuple (Tuple)
- Set
- The Dictionary
In Python3, Number supports the types int, float, bool, and complex.
But there is only one integer type, int, which is represented as a Long integer. There is no Long in Python2.
Also, the built-in type() function can be used to query the object type to which the variable refers:
A, b, c, d = 10, 1.55, True, 4+2j print(type(a), type(b), type(c), type(d))Copy the code
A, b, c, and D are assigned to each variable, and then the type is printed.
<class 'int'> <class 'float'> <class 'bool'> <class 'complex'>
Copy the code
These are int, float, bool, complex.
Python operators
As in most programming languages, Operations in Python can generally be divided into two classes based on the resulting values, those that are concrete and those that are Boolean. Among them, the results for the specific values include: arithmetic operation, assignment operation; The result, in turn, is Boolean: comparison operation, logical operation, and member operation. Here are five common operators:
1. Arithmetic
Arithmetic operations include addition, subtraction, multiplication, division, remainder, exponentiation and rounding.
2. Comparison operation
Comparison operations include: greater than, less than, equal to, not equal to, greater than or equal to, and less than or equal to.
3. Assignment
The equal sign (=) is used to assign values to variables. The left side of the equal (=) operator is a variable name, and the right side of the equal (=) operator is the value stored in the variable. Assignment operation includes simple assignment operation and arithmetic assignment operation.
4. Logical operation
The result of a logical operation is a Boolean value. The operations include and, or, and not.
5. Member operation
Member operations, used between variables and sets, include: in and not in operations.
Python’s comments
In work, in order to ensure the readability and correctness of the code, it is very convenient to keep a certain code comment for yourself and others to read the code. There are single-line comments and multi-line comments in Python. Common comments are as follows:
1. One-line comment beginning with #
Print ("Hello, Python!" )Copy the code
Single-line comments in Python start with #.
2. Use three single quotation marks for multi-line comments
"" Multi-line comments, using three single quotes. Multi-line comments, using three single quotes. ''' print("Hello, Python!" )Copy the code
3. Use three double quotation marks for multi-line comments
""" Multiple line comments, using three double quotation marks. Multi-line comments, using three double quotes. """ print("Hello, Python!" )Copy the code