Catalog
Basic understanding
Basic type conversion function
print function
input function
if sentence
Thinking questions
A program needs to run three cores of hardware :CPU, Memory , Hard disk .
CPU: Responsible for data processing and calculation .
Memory : Fast , Small space , There are many chips on the memory module , Memory modules usually have only 4G,8G,16G,32G.
Hard disk : Slow speed , The space is large , An important parameter when buying a hard disk is “ speed ”, The faster the speed, the faster the reading speed .
stay python There is no need to specify the type of variables defined in .
Data types can be divided into numeric and non numeric types .
Digital : integer , floating-point , Boolean type , Plural .
Non digital : character string , list , Tuples , Dictionaries .
int(xx) function
effect : hold xx To integer .
str(xx)
effect : hold xx To string .
chr(xx)
effect : hold xx To a character .
More functions can be self Baidu .
stay python Use this function in to print content .
input Function when there is something in parentheses , It will prompt the user to enter relevant information as a prompt . It should be noted that ,input The return value of is a string , If the content needs to be ''445 '' When the string of is converted to an integer , You can use int() function .
hh = int(input(" Please enter age :")) print(hh) print(type(hh)) #type Determine the variable type
if age > 30: print(age) # if How to write sentences , After the condition is written, enter four spaces or one tab, But remember not to mix the two in a program .
Be careful ! Be careful ! Be careful ! Class III warning .
if Statement is a block of the adjacent indented code below .
If the conditions are met , Three print Metropolitan output , If you don't want to output the last one, you can remove the indentation .
# Scissors, stone, and cloth
player = int(input(" Please enter scissors (1) stone (2) cloth (3)"))
comp = 3
if ((player == 1 and comp == 3)
or (player == 2 and comp == 1)
or (player == 3 and comp == 2)):
print(" Is too weak , Computer brother ")
elif (player == 1 and comp == 1) or (player == 2 and comp == 2) or (player == 3 and comp == 3):
print(" It's a draw ")
else:
print(" Ah ah , I am lost ")
python It is extremely easy to read , So how to wrap a line if you encounter a particularly large line of code ?
example : Aforementioned if The statement encloses the judgment condition with two parentheses , Be careful not to run into colons . Then press or Line break , Keep... On each line 8 A space .