Python user interaction, formatted output

Source: Internet
Author: User

Comments in Python

单行的话用“#”号注释,多行注释,可以用三个单引号,或三个双引号‘‘‘ ‘‘‘或 """ """

User input in Python

1.

#!/usr/bin/env python#_*_conding:utf-8_*_name = input("What is your name?")print("hello" , name)

2.

#!/usr/bin/env pythonname=input("name:")age=input("age:")job=input("job:")info=‘‘‘------info of %s------Name: %sAge: %sJob: %s‘‘‘%(name,name,age,job)print(info)

3.

#!/usr/bin/env pythonname=input("name:")age=input("age:")job=input("job:")info=‘‘‘------info of %s------Name: %sAge: %dJob: %s‘‘‘%(name,name,age,job)print(info)#这里运行的话会报错:    Traceback (most recent call last):  File "input.py", line 12, in <module>    ‘‘‘%(name,name,age,job)TypeError: %d format: a number is required, not str#这里需要强转义#!/usr/bin/env pythonname=input("name:")age=int(input("age:"))    #请注意这里的强转义job=input("job:")info=‘‘‘------info of %s------Name: %sAge: %dJob: %s‘‘‘%(name,name,age,job)print(info)**#Note: %s表示字符串string的字意思,$d表示整数,int的字思,%f表示浮点数**

4.

#!/usr/bin/env pythonname=input("name:")age=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, 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.