Python string formatting

Source: Internet
Author: User

character formatting output
    1. placeholder%s s = string---> string

    2. %d d = dight-----> integer type

    3. %f f = float-----> float type

Format Output format:

      

Name = Input ("name:") age = input ("age:") job = input ("job:") salary = input ("salary:") msg = "" "---------  Info of%s---- ---------Name =%sage =%sjob =%ssalary =%s "" "% (name,name,age,job,salary) Print (msg)

  

%s is a string placeholder, and each placeholder corresponds to the value of each string, and the order cannot be one by one random.

The output results are as follows:

Determines whether a user enters an integer as a number

Name = input ("name:") age = int (input ("age:")) job = input ("job:") salary = input ("salary:") if salary.isdigit (): #长得像不像数字如, ' 200d ', ' 200 ' if it is performed salary = int (salary)    salary = int (salary) else: #否则输出 print ("must input Dight")    print ("must Input digit ") #如果否则条件执行为 exit (must input Digit) The result is Exit program prompt must inpput digit msg =" ""---------  info of%s------ -------Name =%sage =%sjob =%ssalary =%syou'll is retire%s year "" "% (name,name,age,job,salary,65-age) print (msg)

Input salary:20000d

Input results

  

Python string formatting

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.