python variablesis a knowledge point that can't be bypassed in programming,
Python
variables, the code works correctly, and the value is especially important.
variablesstored in-memory
value, which means that when a variable is created, it is in memory
open up a spaceBased on
variablesData type, the interpreter allocates the specified memory and determines what data can be stored in memory, so
variablesYou can specify a different
Data Type, these variables can be
storing integers,
decimalOr
character。
assigning values to variables
variable Assignments in Python do not require a type declaration, and each variable is created in memory, including 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 . For example:
#!/usr/bin/python#-*-Coding:utf-8-*-counter = + # Assignment integer variable miles = 1000.0 # float name = "John" # string Print Co unter Print miles Print name
In the above example, 100,1000.0 and "John" are assigned to the COUNTER,MILES,NAME variable respectively.
Executing the above program will output the following results:
100
1000.0
John
assigning values to multiple variables
Python allows you to assign values to multiple variables at the same time. For example:
A = b = c = 1
The above example creates an integer object with a value of 1 and three variables allocated to the same memory space.
You can also specify multiple variables for multiple objects. For example:
A, b, C = 1, 2, "John"
In the above example, two integer objects 1 and 2 are assigned to variables A and B, and the string object "John" is assigned to variable C. Identification method: The left and right sides of the equal sign as characters, each corresponding.
For more information, please visit the PHP Chinese Web Python tutorial section.