%https://zhuanlan.zhihu.com/p/90439125
https://blog.csdn.net/sunxb10/article/details/81036693
# 使用元组
name = "Eric"
age = 3
print("Hello, %s. You are %s." % (name, age))
# Hello Eric. You are 3.
format()
- 设置指定位置
print("{1} {0} {1}".format("hello", "world")) # 设置指定位置
# world hello world
- 设置参数
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 参数获取方式:直接指定;字典;列表
print("网站名:{name}, 地址 {url}".format(name="菜鸟教程", url="www.runoob.com"))
# 通过字典设置参数
site = {"name": "菜鸟教程", "url": "www.runoob.com"}
print("网站名:{name}, 地址 {url}".format(**site))
# 通过列表索引设置参数
my_list = ['菜鸟教程', 'www.runoob.com']
print("网站名:{0[0]}, 地址 {0[1]}".format(my_list)) # "0" 是必须的
# 网站名:菜鸟教程, 地址 www.runoob.com
f-strings
注意:该函数仅适用于3.6及以上版本
- 时间
import datetime
e = datetime.datetime.today()
print(f'the time is {e:%Y-%m-%d (%a) %H:%M:%S}') # datetime时间格式
# the time is 2021-10-08 (Fri) 11:38:52
- 保留小数
d = 0.5 + 2.5j
print(f'd is {d:30.3e}') # 宽度30位,科学计数法,3位小数
# d is 5.000e-01+2.500e+00j



