Python中字符串常用的方法
来源:互联网 发布:mac连不上wifi 编辑:程序博客网 时间:2024/06/10 18:12
python中字符串常用的方法:
information = "this is shanghai city,"information1 = "It's very bustling"aaa = "I come from {city},and myhometown is {name}"print(information.center(50,'*')) #长度为50,并且居中print(information.find('s')) #查找字符串的索引位置,默认是第一个,和index方法类似print(information.startswith('th')) #判断字符串以什么开头print(information.strip()) #去掉字符串两头的空格和换行符print(information.split('i')) #去掉字符串两头的空格和换行符print(aaa.format(city='石家庄',name="行唐")) #字符串的格式化另一种方式print(aaa.format_map({'city':'石家庄','name':"行唐"})) #字符串的格式化,中间传的是字典,这种不常用print(information.isdigit()) #判断字符串是不是数字print(information.lower()) #小写print(information.upper()) #大写print(information.replace('this','This',1)) #替换,后的1表示,替换的次数print(''.join([information,information1])) #字符串拼接,中间用列表,元组,字典的形式传都可以
用python写九九乘法表(仅作为一种娱乐)
python2.7里面的代码
#!/usr/bin/env pythonfor line in range(1,10): for width in range(1,line+1): print "%s*%s=%s " %(line,width,line*width), print
python3.x里面的代码
#!/usr/bin/env pythonfor line in range(1,10): for width in range(1,line+1): print("%s*%s=%s " %(line,width,line*width),end="") print()
阅读全文
0 0
- python中字符串的常用方法
- Python中字符串常用的方法
- Python字符串中常用的方法
- python中字符串常用方法
- 常用的Python字符串方法
- Python字符串的常用方法
- python 判断字符串中字符类型的常用方法
- python中字符串(str)的常用处理方法
- 字符串中常用的方法
- 字符串中常用的方法
- Python字符串常用方法
- python常用字符串方法
- Python 字符串常用方法
- python 字符串常用方法
- Python中字符串的方法
- Python对字符串的常用处理方法
- Python 几个字符串常用的方法
- Python中字符串的常用操作
- test
- IIIT5K数据提取预处理
- POJ 2533 最长上升子序列
- 浏览器默认样式清除
- APP启动页背景颜色变化
- Python中字符串常用的方法
- Android动画
- 中文乱码 URLEncode之后,后台获取仍是乱码问题详解
- vue2.0实现一个简单的轮播图
- java中打开文件的方法以及文件路径的写法
- viewpager设置子item宽度
- openwrt编写hello_world ipk
- MVC模式 探索
- hdu 1392(凸包)