Basic grammar_01

 

input: Receive user input information;

1  #Use input to get the necessary information 
2 name =input( " Please enter your name: " )
 3  
4  #Enter the name: Dashen 977, or other name information you want to enter 
5  
6  #Print the obtained name information: 
7  print ( " Your name is: %s " % name)
 8  
9  #The output is as follows: Your name is: Great God 977 or the information you entered

 variable type conversion

#Print age: 
age = input( " Please enter your age " )
 #The input number is 18

# When python receives user keyboard input, the default is string type, that is, "input number" 
age_num = int(age)

#If you are older than 18, congratulations, you are an adult 
if age_num > 18 :
     print ( " Congratulations, you are an adult " )

 Identifier: It can only be composed of letters, numbers or underscores (_), and cannot start with numbers. It is recommended not to start with underscores, and give a familiar name. Such as english_score. And Pinyin is not recommended.

Keywords:

  Some identifiers in python have special functions, which are called keywords.

#View the keywords defined in python 
import keyword
keyword.kwlist

 Operators: + - * / , the usage is the same as addition, subtraction, multiplication and division in mathematics


#Speak a little special usage # Print 20* 
#General writing: print ( " ********** " )


# print 20 with operator * 
print ( " * " * 20)

Print multiple variables at once:


#Print multiple variables at a time # Define variable name and content 
name = " zhangsan " 
age = 20 
addr = " Haidian District, Beijing... "

#Print output, when printing multiple variables at one time, the variable name is placed in parentheses 
print ( " Name is: %s, age is: %d, address is: %s " %(name,age,addr))

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325227280&siteId=291194637