Article From:https://www.cnblogs.com/oddcat/p/9648590.html

Formatted output, in addition to formatted output similar to C language, there is str. format () method, Python built-in format () function, allowing the user to output values in the form of parameters, call the format () function, in Python interactive shEll, throughhelp(format) Commands can get detailed information:

 

Therefore, if value is a variable of type STR, thenformat(value,format_spec)  <==>  value.format(format_spec) 

When value is not STR type, for exampletype(value) == int At the time,value.format(format_spec) You will report wrong.

 Butformat(value,format_spec) Can run:

 

One Reply to “Python — format () /str.format () function”

Leave a Reply

Your email address will not be published. Required fields are marked *