Concatenation of strings formatted output

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.