本文学习自https://blog.csdn.net/duxin_csdn/article/details/88583429
理解:
f’’ 字符串类型与 format 函数的使用类似,但更简单
format函数
>>> name = 'Alex'
>>> age = 25
>>> sex = 'Male'
>>> introducation = 'My name is {name},I am a {sex},and I am {age} years old.'.format(name=name,sex=sex,age=age)
>>> introducation
'My name is Alex,I am a boy,and I am 25 years old.'
f’'字符串
1). 使用f字符串进行拼接字符串:
>>> introducation = f'My name is {name},I am a {sex},and I am {age} years old.'
>>> introducation
'My name is Alex,I am a boy,and I am 25 years old.'
2). f字符串使用对象操作
>>> info = {'name': 'Alex', 'age': 25, 'sex': 'boy'}
>>> introducation = f'My name is {info["name"]},I am a {info["sex"]},and I am {info["age"]} years old.'
>>>
>>> introducation
'My name is Alex,I am a boy,and I am 25 years old.'