Python 自学小知识留存 2018年11月12日更新
2018-09-26 20:13
537 查看
版权声明:请勿随意转载复制,转载请注明地址出处 https://blog.csdn.net/songlh1234/article/details/82853539
1.Python format 格式化函数,format 函数可以接受不限个参数,位置可以不按顺序。
简单举例:更多参考http://www.runoob.com/python/att-string-format.html
2.Python 字典(Dictionary) keys()方法,用dict.keys()方法返回一个字典dict的所有键。
[code]test = { "statusCode": 200, "data": { "totoal": "5", "height": "5.97", "weight": "10.30", "age": "11" }, "msg": "成功" } def get_keyvalue(data): for key in data.keys(): key_value = data.get(key) if isinstance(key_value, dict): get_keyvalue(key_value) else: print('key='+str(key)+' '+'value='+str(key_value)) print('直接使用data.keys()方法取出key'+str(test.keys())) print('使用递归循环取出data.keys') get_keyvalue(test)
3.Python startswith() 方法用于检查字符串是否是以指定子字符串开头,如果是则返回 True,否则返回 False
4.Python isdigit()方法
判断字符串中的字符是否只由数字组成,如果是的话返回True,如果否返回False
5.Python isinstance(str, type)用法
判断一个对象是否是一个已知的类型isinstance (a,int);isinstance (a,str);isinstance (a,(str,int,list));isinstance (a,dict)等
6.python split()的用法,将字符串根据某个字符进行分割
[code]test = "aaa/bbbb" print(test.split('/')[0]) print(test.split('/')[1])
7.python join()的用法,将序列中的元素以指定的字符连接生成一个新的字符串
[code]str = "-" seq = ("a", "b", "c") # 字符串序列 print(str.join(seq)) list = ['1', '2', '3', '4', '5'] print(''.join(list))
结果:
[code]a-b-c 12345
8.Python ljust() 方法返回一个原字符串左对齐,并使用空格填充至指定长度的新字符串。如果指定的长度小于原字符串的长度则返回原字符串
[code]str1 = "this is string example....wow!!!" print(str1.ljust(50, '*'))
结果:this is string example....wow!!!******************
阅读更多相关文章推荐
- python基础知识总结(不断更新。。。。)
- python 模块知识(持续更新......)
- python知识备忘集合(持续更新)
- 伪知识之通俗易懂得解析python仓库的体系结构持续更新:【内向即失败--王奕君】
- Start Python 学习笔记(琐碎知识,持续更新。。。)
- Python初学笔记——琐碎知识,based on 2.7.3,持续更新中
- Python自学笔记之基础知识回顾2
- 自学python途中,更新了一个数学的知识点(四舍六入五成双)
- Python自学笔记(一)(Python基础知识)
- python基础知识总结(不断更新)
- python 各种问题处理更新 何不一次性搞定全部编码知识
- Python做数据分析中需要掌握的命令行知识-持续更新中
- Python小知识的记录(持续更新)
- DayDayUP_Python自学记录[1]_Python基础知识
- 伪知识之了解python中_init_.py的含义及作用持续更新:【内向即失败--王奕君】
- 自学Python四 爬虫基础知识储备
- python自学总结
- Python初学笔记:Python编程基础知识
- python 字典 一些总结(持续更新)