Annotations are not translated into machine code in the interpreter , Its existence does not affect the function of the program
#
''' Multiline comment content '''
perhaps """ Multiline comment content """
Annotate the code with , Improve the readability of the code .
identifier ---- Naming requirements
python Identifier requirements , There are letters 、 Numbers 、 Underline composition , And numbers don't start
keyword ---- python Some identifiers with special functions or special meanings in , It can't be used for other purposes !
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
# View reserved words
from keyword import kwlist
print(kwlist)
Digital data : Data used to represent the size of a numeric value
The way in which numerical data is represented in a program , It's the same way in mathematics that it's a number , And support scientific counting
The type corresponding to the number : Digital data is divided into integer types (int
- Integers ) And floating point (float
- decimal ) Two kinds of
Text data :
It is used to represent the data corresponding to text information ,
Representation : The text data must be enclosed in quotation marks
type : character string (str
)
Boolean data :
Only True
and False
Two values True To affirm 、 really ;False Said the false 、 no (True and False Is the key word )
Representation : direct writing True、False.
type : Boolean (bool
)
Null value :
Only None
(None Is the key word )
type :NoneType
Get data type : type( data )
Gets the type of the specified data
Type conversion : Type name ( data )
The specified data is converted to the specified type
int and float
They can switch to each other ,int turn float Add ' .0', float turn int Go directly to the integer part of the decimal
Strings and numbers and conversions
String after removing quotation marks A string that is itself an integer can be converted to int
String after removing quotation marks A string that is itself a numeral can be converted to float
Other data are transferred to str All types
All the data can be converted into str, When converting, directly put quotation marks outside the original data
bool Convert numbers True -> 1/1.0
False -> 0/0.0
Other data are transferred to bool All types
All the data can be converted into bool, be-all Both zero and null values are False
, Everything else is True
def print(self, *args, sep=' ', end='\n', file=None): # \n Namely
pass
# print : Is to display the data in the program on the console ( Print ) come out , All the contents displayed in the console , It must be used in the program print Printed content
print
Print a data : print( data )
print
Print multiple data : print( data 1, data 2,.......)
print
During operation , Will print the data first , The data will be printed after printing end
Value (end
The default value of is line feed )print
When printing multiple operations , Will insert... Between values sep
Value , Control when printing multiple data at the same time , A separator between data and data (sep
The default value of is space )def input(*args, **kwargs):
pass
# The program gets data from the console
Variable = int(input(" Enter the prompt message ")) ------ Enter the prompt message , And save the input to the variable