兄弟萌,话不多说,show me the code!
"""格式化输出"""
"""一、format,可自定义名称"""
print('{a} {tom} {a}'.format(tom='hello',a='world'))
"""二、format, 数字保留2位"""
print('{number} is {num:.2f}'.format(number='firstNum',num=1.2345))
"""三、不用format,使用f关键字"""
cnt =2
cnt2 = 5.5677
print(f'cnt = {cnt}, cnt2 = {cnt2:.2f}')
"""四、使用%关键字"""
hello = 'hello'
number = 2.236
print("这是我第%.2f次说%s" % (number,hello))
world hello world
firstNum is 1.23
cnt = 2, cnt2 = 5.57
这是我第2.24次说hello