您的位置:首页 > 编程语言 > Python开发

编程小白的第一本 python 入门书 学习笔记02 第三章 变量与字符串

2018-02-10 15:56 981 查看
常用命令:赋值a=12 输出print(a) 写入file=open(r'C:\Users\Mean\Desktop\test.txt','w')file.write('HelloWorld')file.close() 注意:单引号等价于双引号,三引号可换行。 连接字符串num = 1 string ='1' num2 = int(string) #转换类型 print(num + num2)
 字符串分片索引name ='My name is Mike' print(name[0])'M' print(name[-4])'M' print(name[11:14])  # from 11th to 14th, 14th one is excluded 'Mik' print(name[11:15])  # from 11th to 15th, 15th one is excluded 'Mike' print(name[5:])  'me isMike' print(name[:5])  'Myna'
 字符串方法lena=len('zhangsan') 字符串方法replacephone_number= '1386-666-0006'hiding_number= phone_number.replace(phone_number[:9],'*' * 9) print(hiding_number)
*********0006
 字符串方法formatprint('{}a word she can get what she {} for.'.format('With','came')) 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'))
 city =input("write down the name of city:") url= "http://apistore.baidu.com/microservice/weather?citypinyin={}".format(city)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  笔记 Python
相关文章推荐