编程小白的第一本 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)
字符串分片索引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 入门书 学习笔记07 第八章 开始使用第三方类库
- Python(编程小白的第一本 Python 入门书) 学习笔记2——代码练习
- 编程小白的第一本 python 入门书 学习笔记05 第六章 数据结构
- 编程小白的第一本 python 入门书 学习笔记04 第五章 循环与判断
- 编程小白的第一本 python 入门书 学习笔记01 第二章 安装Python环境
- 编程小白的第一本 python 入门书 学习笔记06 第七章 类与可口可乐
- 笔记|《简明Python教程》:编程小白的第一本python入门书
- 笔记|《简明Python教程》:编程小白的第一本python入门书
- Python学习笔记:02 基础:变量、整数、字符串、赋值、基本输出、注释、代码块
- 零基础 入门学Python-学习笔记第二讲(变量与字符串)
- 【零基础入门学习Python笔记003】插曲之变量和字符串|课习题答案
- Python入门----变量(菜鸟教程的学习笔记)
- python基础教程学习笔记 第三章 字符串
- Python学习笔记(一)--Python基础知识:变量、数据类型、模块与字符串
- python小白入门学习笔记-爬虫入门
- python核心编程学习笔记-2016-09-03-02-图形化用户界面编程(三)
- python核心编程学习笔记-2016-07-20-02-整型对象缓存
- 【零基础入门学习Python笔记015】字符串:格式化
- python核心编程学习笔记-2016-07-23-02-切片索引
- Python学习笔记2(02-03):变量+运算符和表达式