Today is mainly user input and output, character stitching.
In Python, a multiline comment is 3 single quotation marks or double quotation marks that are preceded by a # number, as follows.
‘‘‘
Name = "Xiaoming"
Print (name)
‘‘‘
# name = "Xiaoming".
In Python, a single double quote function, unless it is a statement in the fear of single or double quotation marks too much, the characters are not clear, only back to the single double quotation marks, as follows.
Print ("I ' M xiaoming")
%s is a string, %d is a number, %f is a floating-point number, as follows:
Name = input ("Name:")
Age = Input ("Age")
Job = input ("job")
info = ""
-----Info of%s-----
name:%s
age:%s
job:%s
"% (Name,name,age,job)
Print (info)
Execute the above procedure
age:%s Change age:%d, execute the program
The error shows that%d input is not a str string, because the python default input is a string type,%d indicates that the character type received by age can only be integer type, causing the program to error.
Enter print (type age) under age = Input ("Age:") to see the type of character entered.
You can see that it is a character type, not an integer type, and you can change the age = Input ("Age:") to age = Int (input ("Age:")) and execute the program.
Here int is the conversion of input character type to integer, if you want to convert the integer type to a string, you need to change print (type (age)) to print (type (age), type (str))
You can see that the integer type has been converted to a string type.
The following is a two-segment code is the other two ways of character stitching
1>
Name = input ("Name:")
age = Int (input ("Age:"))
Print (Type (age), type (str))
Job = input ("Job:")
Salary = input ("Salary:")
info = ""
------info of {_name}-----
Name:{_name}
Age:{_age}
Job:{_job}
Salary:{_salary}
". Format (_name=name,
_age=age,
_job=job,
_salary=salary)
Print (info)
This is replaced by the _name instead of the variable name,_age age,_job instead of the job,_salary instead of salary
2>
Name = input ("Name:")
age = Int (input ("Age:"))
Print (Type (age), type (str))
Job = input ("Job:")
Salary = input ("Salary:")
info = ""
------info of {0}-----
NAME:{0}
Age:{1}
JOB:{2}
SALARY:{2}
". Format (name,age,job,salary)
Print (info)
Here is the substitution variable in order.
Today's share to the end of this, thank you!
Python learning Essay (ii)