python实用技巧
来源:互联网 发布:java引用xml文件 编辑:程序博客网 时间:2024/05/28 16:08
很多python的小技巧,实际调试和工程应用中都可以用到
1、print打印分割符
直接用print中参数sep进行换行,分割线的快速打印。
>>> print('This is a pig','This is a dog','This is a cat')This is a pig This is a dog This is a cat>>> print('This is a pig','This is a dog','This is a cat',sep='\n')This is a pigThis is a dogThis is a cat>>> print('This is a pig','This is a dog','This is a cat',sep='\n-----------\n')This is a pig-----------This is a dog-----------This is a cat
2、zip压缩tuple,逐个元素提取打包
zip命令可以对tuple等可以迭代的元素进行分类打包
>>> name = ['pig','dog','cat']>>> price = ['100','150','200']>>> for name,price in zip(name,price): data={ 'name':name, 'price':price, } print(data) {'name': 'c', 'price': '2'}{'name': 'a', 'price': '0'}{'name': 't', 'price': '0'}
阅读全文
0 0
- Python实用技巧
- Python实用技巧
- Python 实用技巧
- python实用技巧
- Python 实用技巧(上)
- Python上的实用技巧
- 30个Python实用技巧
- python实用技巧(一)
- python实用技巧(二)
- python实用技巧(三)
- python实用技巧(四)
- Python初学者实用技巧
- Python实用技巧-成为Pythoner必经之路
- Python实用技巧-成为Pythoner必经之路
- Python实用技巧-成为Pythoner必经之路
- Python实用技巧-成为Pythoner必经之路
- Python实用技巧-成为Pythoner必经之路
- 实用技巧
- mac终端命令,adb,svn命令总结
- protobuf 使用相关
- 【Scikit-Learn 中文文档】四十五:监督学习:从高维观察预测输出变量
- php的COM组件调用相关(包括com_event_sink的用法)
- javascript 语法基础
- python实用技巧
- LINQ(LINQ to DataSet)
- cifs
- long.tostring()
- js--打卡--12.07 邮件的正则表达式
- SAP间接访问的License策略
- vivado点击xsetup.exe没有反应 最终版
- 5G是真的吗?---凯利讯半导体
- 机器学习该怎么入门?