Python Coding specificationProgramming StyleSyntax requirements: indenting uniform variables
标识符的第一个字符必须是字母表中的字母(大写或小写)或者一个下划线(‘_’)标识符名称的其他部分可以由字母(大写或小写)、下划线(‘_‘)或数字(0-9)组成。标识符名称是对大小写敏感的。例如,myname和myName不是一个标识符。注意前者中的小写n和后者中的大写N。有效标识符名称的例子有i、_my_name/name_23和a1b2_c3.无效标识符名称的例子有2things、this is spaced out 和my-name。
Comments
' Hello world! ' " Hello,my name's Alex Li "' hello,my name ' s Alex Li, this is the first time-to-be-here, it's nice to see you guys."
Variable and Assignment variable types
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. For example:
#coding =utf-8#!/usr/bin/pythoncounter = 100 # Assignment integer variable miles = 1000.0 # floating-point name = "John" # string print Counterprint milesprint n Ame
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:
1001000.0John
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"
For 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.
Get input
#coding =utf-8#!/usr/bin/pythonname = input ("Input your Name:") print (name) input your Name:wangtianwangtian
Python basic syntax