character formatting output
- placeholder%s s = string---> string
- %d d = dight-----> integer type
- %f f = float-----> float type
Format Output format:
Name = Input ("name:") age = input ("age:") job = input ("job:") salary = input ("salary:") msg = "" "--------- Info of%s---- ---------Name =%sage =%sjob =%ssalary =%s "" "% (name,name,age,job,salary) Print (msg)
%s is a string placeholder, and each placeholder corresponds to the value of each string, and the order cannot be one by one random.
The output results are as follows:
Determines whether a user enters an integer as a number
Name = input ("name:") age = int (input ("age:")) job = input ("job:") salary = input ("salary:") if salary.isdigit (): #长得像不像数字如, ' 200d ', ' 200 ' if it is performed salary = int (salary) salary = int (salary) else: #否则输出 print ("must input Dight") print ("must Input digit ") #如果否则条件执行为 exit (must input Digit) The result is Exit program prompt must inpput digit msg =" ""--------- info of%s------ -------Name =%sage =%sjob =%ssalary =%syou'll is retire%s year "" "% (name,name,age,job,salary,65-age) print (msg)
Input salary:20000d
Input results
Python string formatting