Home >Backend Development >Python Tutorial >Automated development using Python - introduction to variables, data types and operation methods
1. Variables
Variable definition: Variables are used to store information to referrenced and manipulated in a computer program.
Used to Store the intermediate operation results of the program running
Identification
Storage
Variables are used in the program A variable name means
The variable name must be a combination of uppercase and lowercase English, numbers and _, and cannot start with a number
Sensitive to case
Recommended camel case naming method, such as myFirstName, myLastName
Keywords cannot be declared as variables
In Python, the equal sign = is an assignment statement, and any can be Data type is assigned to a variable. The same variable can be assigned repeatedly, and it can be a different type of variable
##myFisrtName = "Jonathan" myLastName ="Ni" |
##Please do not equate the equal sign of the assignment statement with the mathematical equal sign. For example, the following code:
8 x = x + 2
|
Understand mathematically x = x +
2is not established. In the program, the assignment statement first calculates the expression x + 2 on the right side, obtains the result 10, and then assigns it to the variable x. Since the previous value of x was
8, after reassignment, the value of x becomes 10.
It is very important to understand the representation of variables in computer memory, as shown below in declaring variables and assigning values.
a = "ABC" |
Constant
##
Summary: Inside the computer, any data is regarded as an "object", and Variables are used in programs to point to these data objects, and assigning values to variables associates data with variables.
2. Data types A computer is a machine that can do mathematical calculations. Computer programs naturally deal with various numerical values. In addition to numerical values, computers can also process various data such as text, graphics, audio, video, web pages, etc. Different data requires different data types to be defined. 1. Numbers Integers : The representation method is the same as the mathematical writing method, such as 1, -100, 0, 1000, etc. Or hexadecimal representation, 0xffffff, 0xabcd, etc. Floating point numbers: that is, decimals, such as 0.99, -1.25, 88.88, etc. Or expressed in scientific notation 1.23e8, 1.2e-8, etc. Complex numbers: composed of real part and imaginary part grouped, general form It is x + yj, such as (-5+4j), etc. There is no size limit for numbers. If they exceed a certain range, they are directly expressed as inf(Infinite) 2. StringA string is any text enclosed in single quotes ' or double quotes ", such as 'abc', "XYZ", etc. ' or " itself is just a representation, not part of the string. For example, 'abc' only has three characters: a, b, and c. If ' itself is also a character, it can be enclosed by "", for example "I'm OK"The characters included are I, ', m, space, O, K these 6 characters. Strings containing both ' and " can be identified by the escape character \. For example, 'I\'m \"OK\"!'means I' m "OK"! escape characters can escape many characters, such as \nrepresents a newline, \t represents a tab character, \\ represents the characters \ If there are many line breaks inside the string, you can use '''.....'''The format represents multi-line content. Common string functions#string
method returns the characters. String length.
|
The above is the detailed content of Automated development using Python - introduction to variables, data types and operation methods. For more information, please follow other related articles on the PHP Chinese website!