9 月 152020
#字符串格式化符,不同写法,效果相同
print('{} a word she can get what she {} for.'.format('With','came'))
#对字符串中的“空”使用.format()处理
print('{preposition} a word she can get what she {verb} for'.format(preposition = 'With',verb = 'came'))
#字符串中的“空”值可以是变量
print('{0} a word she can get what she {1} for.'.format('With','came'))
#字符穿中的“空”值按顺序填入
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
With a word she can get what she came for.
With a word she can get what she came for
With a word she can get what she came for.
PS C:\Users\harveymei>
#字符串格式化符
city = input("write down the name of city:")
#通过用户输出传入变量,使用变量值作为字符串中的填空值
url = "http://apistore.baidu.com/microservice/weather?citypinyin={}".format(city)
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
write down the name of city:
PS C:\Users\harveymei>