Python | Input and Output | Format character

Source: Internet
Author: User

1 #Encoding:utf-82 3 #input in Python3 equivalent to raw_input in Python2 (raw)4Content = input ('Please enter the content, which is treated as a string:')5 Print(content)6 7 #You can also use the contents of input as code to handle8Content = eval (input ('Please enter the content, which is treated as code:'))9 Print(content)Ten  One #formatted output AName ='Marry' -Age = 18 - Print('My name is: {0}, my age is: {1}'. Format (name, age)) the Print('My name is:%s, my age is:%d'%(name, age)) -  - #Output to File -f = open ("Test.txt","W") + Print("Hello Word", file=f) -  + #output does not wrap automatically A Print("Hello Word", end="") at  - #Add delimiter - Print("1","2","3", sep=",") -  - #Immediate Output - #if the content to be output has a newline, it is output immediately and does not stay in the buffer in #If there is no line break, the output is not immediately - #solution is flush = True to Print("Hello Word", flush=True) +  - #format character theGrade = 89 * Print("%10d"%grade) $ Print("%-10d"%grade)Panax Notoginseng Print("% d"%grade) -  the #Clock Representation +m = 5 As = 8 the Print("%02d:%02d"%(M, s)) +  - #Decimal Precision $F = 43.5 $ Print("%f"%f) - Print("%.2f"%f) -  the #Convert to octal - Print("%o"% 100)Wuyi  the #Convert to hexadecimal - Print("%x"% 100) Wu  - #Scientific notation means About Print("%e"% 1000000000) $ Print("%E"% 1000000000) -  - #automatically converted to integers or decimals or scientific notation (when more than six digits) represents - Print("%g"% 23) A Print("%g"% 23.34) + Print("%g"% 12000000000) the  - #converts a number to its Unicode corresponding value $ Print("%c"% 19997) the  the #Percentage Representation the #escape% with percent theGrade = 89 - Print("%d%%"% 89)

Python | Input and Output | Format character

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.