今天上课有几道小题输出总是报错,因此回去百度了下,在这里整理了一些python的输出方式以防忘记
- print(f"…{data}")
a = 250
b = "0.618"
c = 0.33
print(f"输出:{a}")
print(f"输出:{a}, {b}, {c}")
- 字符串拼接
a = 250
b = "0.618"
c = 0.33
print("输出:" + b)
print("输出:" + str(a) + " " + b + " " + str(c))
- print(" {} ".format(data))
a = 250
b = "0.618"
c = 0.33
print("输出:{}".format(a))
print("输出:{}, {}, {}".format(a, b, c))
print("输出:{0}, {1}, {2}".format(a, b, c))
print("输出:{2}, {0}, {1}".format(a, b, c))
- print(" %d " % (data))
a = 250
b = "0.618"
c = 0.33
print("输出:%d" % a)
print("输出:%d" % (a))
print("输出:%d, %s, %f" % (a, b, c))
|