1. Variables
Variable type
The value that the variable is stored in memory. This means that there is a space in memory when creating variables.
Based on the data type of the variable, the interpreter allocates the specified memory and determines what data can be stored in memory.
Therefore, variables can specify different data types, which can store integers, decimals, or characters.
Assigning values to variables
Variables in Python do not need to be declared, and the assignment of variables is the process of declaring and defining variables.
Each variable is created in memory and includes information about the identity, name, and data of the variable.
Each variable must be assigned before it is used, and the variable will not be created until the variable is assigned.
The equals sign (=) is used to assign a value to a variable.
The left side of the equals sign (=) operator is a variable name, and the right side of the equals sign (=) operator is the value stored in the variable.
String: Name= "MyName"
Integral type: Number = 100
Floating point: Price = 10.0
Python also supports assigning values to multiple variables at the same time. For example:
A = b = c = 1 (creates an integer object with a value of 1 and three variables allocated to the same memory space.) )
Python can also specify multiple variables for multiple objects:
Name, age, sex = "Tom", All, "M"
Print "%s is a%d%s"% (Name,age,sex) in
Run print output to Tom is a + M
2. Standard data types
Python has five standard data types:
Numbers (digital)
String (String)
List (lists)
Tuple (tuple)
Dictionary (dictionary)
Python's numeric type is used to store numbers, and Python supports 4 different numeric types [int (signed integer), long (or 8 binary and 16 binary), float (floating point), complex (plural)]);
Python strings are a string of characters consisting of numbers, letters, and underscores;
The Python list is the most mundane data type used in Python. The list can accomplish the data structure implementation of most collection classes. It supports characters, numbers, strings, and even lists that can be included.
The list is denoted by []:
list = ["Tom",%, "M"]
Python tuples and lists are similar but can only be read and cannot be modified or deleted.
Tuples are represented by ():
tuple = ("name", "Age", "sex")
The Python dictionary is the most flexible built-in data structure in Python, in addition to the list. A dictionary is a collection of unordered objects. The elements in the dictionary are values by key, rather than the list using offsets to take values.
The dictionary is denoted by {}:
Dict = {"Name": "Tom", "Age": +, "sex": "M"}
Print Dict[name] Output key value is "name" Value Tom
Learn the basics of Python----