string concatenation format output is to edit the content that needs to be output to a variable, and then output to the screen.
Method One
name = input(‘your name:‘)age = int(input(‘your age:‘)) # int() str转int。job = input(‘your job:‘)info = ‘‘‘---------- info of %s --------- Name : %s Age : %dJob : %s‘‘‘ % (name,name,age,job) # 此处 % 为连接符,把变量的值连接起来,顺序不能颠倒。print(info)
Placeholder
%s s=string, omnipotent, no error.
%d d=digit, integer type.
%f f=float, Decimal, save 6 decimal places by default, the value of the 6th decimal place to see the 7th decimal place, will be rounded.
?? %.3f, specify to save 3 decimal places.
name = input(‘your name:‘)age = int(input(‘your age:‘)) # int() str转int。job = input(‘your job:‘)info = ‘‘‘---------- info of {_name} ---------Name : {_name}Age : {_age}Job : {_job}‘‘‘ .format(_name=name,_age=age,_job=job)print(info)
Method Three
name = input(‘your name:‘)age = int(input(‘your age:‘)) # int() str转int。job = input(‘your job:‘)info = ‘‘‘---------- info of {0} ---------Name : {0}Age : {1}Job : {2}‘‘‘ .format(name,age,job)print(info)
string concatenation format output, the proposed use of method two and method three, plus the addition of the connection method for splicing output, not recommended, each additional plus will occupy some memory space, execution efficiency is low.
Concatenation of strings formatted output