This article mainly shares with you a detailed explanation of the basic data types of Python. Friends who need it can take a look at
Python’s own shell
Go to the directory where the python file is located, Then run
python xxx.py (such as C:\work>python hello.py)
3.pythoncharm and other IDE
4.sublime Text etc. Plug-in editor
Python data types are divided into variable types and immutable types
Python basic data types
The variable type is
Number (number):
Including int, float, bool, complex (plural).
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 objects of different types through assignment.
3. The division of numerical values (/) always returns a floating point number. To obtain an integer, use the // operator.
4. During mixed calculation, Python will convert integers into floating point numbers.
5. Power a**b
6. Complex number a+bj or complex(a,b)
String (string):
List (list)
Dictionary (dictionary)
Sets (set)
A set (set) is an unordered sequence of non-repeating elements.
The basic function is to perform membership testing and remove duplicate elements.
You can use curly brackets { } or the set()
function to create a set. Note: To create an empty set, you must use set() instead of { }, because { } is used to create an empty dictionary.
1 2 3 4 5 6 7 8 9 10 |
|
The immutable type is
Tuple (tuple)
List content
Constructing a tuple containing 0 or 1 elements is special
1 |
|
==Tuples can also be spliced using the + operator. ==
1 2 3 4 5 |
|
==python Description of variables==
The declaration of a python variable is a reference to an object. For a variable type, if its copy changes, it itself will also change
1 2 3 4 5 6 |
|
For immutable types Type, its variable value will not be affected by the copy
1 2 3 4 5 6 7 |
|
Function | Description |
---|---|
int(x [,base]) |
Convert x to an integer |
float(x) |
Convert x to a floating point number |
complex(real [ ,imag]) |
Create a plural number |
##str(x) | Convert object x to string |
repr(x) | Convert object x to expression The formula string |
eval(str) | is used to evaluate the valid Python expression in the string, And return an object |
The above is the detailed content of Detailed explanation of python's basic data types. For more information, please follow other related articles on the PHP Chinese website!