python string format (the format)

 

 Examples are as follows:

The following note!

Finally, a way to remember together before 2.1f % , final exam today python last question in the last two decimal places, does not automatically make zero in this did not last!

Now deprecated above method, with which surface this, directly after the variable number plus a ':', Eau to add a decimal format.

Example:

a,b=input().split()#一行输入多个值再类型转换
print('{0}+{1}={2}'.format(int(a),int(b),int(a)+int(b)))#格式化输出,字符串之间不再有多余的格

result:

2 3
2+3=5

 

Published 81 original articles · won praise 91 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_44593822/article/details/103597280