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