First, the output statement input output statement print
Example: user input
1 username = input( " username: " )
2 #characters displayed in the variable name
3 password = input( " password:)
4 print (username,password)
2. Formatted output
Example: Introduction
1 name = input( " name: " ) #Character type 2 age = input( " age: " )
3 print (type(age)) #View the type of age typ() output type 4 jop = input( " jop: " )
5 salary = input( " salary: " )
Note: The type obtained from the input is a character type, so what age gets is a character, not a value ; if age gets a value, the type should be converted.
1 age = int(input( " age: " )) # age is an integer
Four ways to format output
- concatenation of strings
1 info1 = """
2 ------------info1 of """ +name+ '''------
3 Name:''' +name+ """
4 Age:""" +age+ '''
5 Jop:''' +jop+ """
6 Salary:""" +salary
7 print(info1)
# String concatenation can only be used for characters
# You can use ''' ''' or """ """ for multi-line output, info1 has been written in two ways
2. #placeholder %s character type, %d decimal integer type, %f floating point type
1 info2= ''' 2 ---------info2 of %s------ 3 Name:%s 4 Age:%s 5 Jop:%s 6 Salary:%s 7 ''' %(name,name,age,jop,salary) #Write 8 in output order print (info2)
3. Use .format()
1 info3 = """ 2 -----------info3 of {name2}------- 3 Name:{name2} 4 Age:{age2} 5 Jop:{jop2} 6 Salary :{salary2} 7 """ .format(name2=name,age2=age,jop2=jop,salary2=salary) #Can be understood as an array 8 print (info3)
4.
1 info4 = """ 2 -----------info4 of {0}------- 3 Name:{0} 4 Age:{1} 5 Jop:{2} 6 Salary:{3} 7 """.format(name,age,jop,salary) 8 print(info4)
3. Operation results