python字符串调用举例
以如下打印为例: my name is tom and my age is 12 方式一 name = 'tom' age = 12 print(f"my name is {name} and my age is {age}") 方式二 name = 'tom' age = 12 print("my name is " + name + " and my age is " + str(age)) 方式三 name = 'tom' age = 12 print("my name is %s and my age is %s" %(name,age)) 方式四 name = 'tom' age = 12 print("my name is {name} and my age is {age}".format(name='tom',age=12)) 方式五 print("my name is {} and my age is {}".format('tom',12)) 方式六 name = 'tom' age = 12 print("my name is {} and my age is {}".format(name,age)) 注意以下调用反而会引起错误 name = 'tom' age = 12 print("my name is {name} and my age is {age