The format string in Python currently has two camps:% and format, which one should we choose?
Since Python2.6 introduced the format-formatted string method, I think the% or format is not a problem at all. Don't believe you look down.
% of disadvantage:
# define a coordinate value c = (+)# use% to format " enemy Coordinates:%s" % c
The above code obviously throws a typeerror like this:
Typeerror:not all arguments converted during string formatting
Like this kind of formatting needs we need to write the following ugly format:
# define a coordinate value c = (+)# Use the% ugly formatting ... " enemy Coordinates:%s " % (c,)
There is no problem with format:
# define a coordinate value c = (in.)# format " Enemy Coordinates: {}" using format . Format (c)
Obviously, the above reason is enough for you to use format for future projects.
Added f-strings to Python3.6:
in[2"q1mi"in[3in[4]: F" My name is {name}. I ' m {age}"out[4"My name is Q1mi.i ' m"
Should I format a string using% or format in Python?