python文件文本操作方法,format的使用

print('{0} a word she can get what she {1} for.'.format('With','came'))
With a word she can get what she came for.

>>> city = input("write down the name of city:")
write down the name of city:guangzhou
>>> url = "http://apistore.baidu.com/microservice/weather?citypinyin={}".format(city)
>>> print(url)
http://apistore.baidu.com/microservice/weather?citypinyin=guangzhou
>>> int('a')
读写文件函数构建:注意文件夹路径在mac和windows上的区别
def text_create(name,msg):
    **desktop_path = '/Users/apple/Desktop/'**
    full_path = desktop_path + name + '.txt'
    file = open(full_path, 'w')
    file.write(msg)
    file.close()
    print('Done')

text_create('hello','hello world')

你可能感兴趣的:(python语言进阶)