# 格式化字符串: 在字符串前加上 f 或者 F 使用 {变量名} 的形式来使用变量名的值 year = 2020 event = 'Referendum' value = f'Results of the {year} {event}' print(f'Results of the {year} {event} \n', value) # : .3f 标示 保留前面的变量值/字面值3位小数 , 3d, 3 则是让盖子段成为最小字符宽度,在使列对齐时作用大 print(f'The value o
1)%格式化方法 >>> a = "this is %s %s" % ("my", "apple") >>> a 'this is my apple' 2)内置方法format(): >>> a = "this is {} {}".format("apple","my") >>> a 'this is apple m
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This PEP proposes a new system for built-in string formatting operations, intended as a replacement for the existing '%' string formatting operator. 1.百分号