The python definition string is usually enclosed in single or double quotes, including the content to be represented, such as:
Name = "Linjunjie" address = ' Taiwan '
If you want to define a string with more than one line, use three single quotes
person = "name=jjjob=geshouage=30" Print (person)
First Interactive program:
Print user-entered content
Name = input ("Name:") Age = input ("Age:") Job = input ("job:") info= '-----------info of ' ' +name+ '---------- ----Name: ' +name+ ' ' Age: ' +age+ ' Job: ' +job+ ' ' print ' (info)
"+" means splicing string variables, similar to JS, a string in the middle of the need to splice variables, this representation is too cumbersome, Python has a simpler way:
The second way of replacing:
Name = input ("Name:") Age = input ("Age:") Job = input ("job:") info= "-----------info of%s--------------name:% sage:%sjob:%s '% (name,name,age,job) print (info)
%s means that the placeholder represents the replacement of the contents of the following parentheses.
The data type received by%s is a string.
The data type received by%d is an integer. The Python default input is a string, if you want to use%d to convert the input content.
string-To-integer:
Age = input ("Age:") print (type (age), type (int))) #<class ' str ' > <class ' int ' >
Integer-To-string:
Age = Int (Input ("Age:")) print (type (age), type (str)) #<class ' int ' > <class ' str ' >
The third Way of replacing:
Name = input ("Name:") Age = Int (Input ("Age:")) Job = input ("job:") info= "-----------info of {_name}---------- ----Name:{_name}age:{_age}job:{_job} ". Format (_name=name, _age=age, _job=job) print (info)
Python user interaction