python.format()函数的简单使用
2018-03-14 11:13
351 查看
python中的format函数:
用于对字符串的格式化
1.通过位置传递
print('{0}xxxxxxxx{1}'.format('这是0要传入的东西','这是1要传入的东西'))
2.通过关键字传递
print('{0}xxxxxxxx{1}'.format(0='xxx',1='xxx'))
如果是字典 print('{keys}xxxxxxxx{values}'.format(**<字典名>))
3.充当数字的千分位分隔符(例如:1,000,000)
print('{:,}'.format(1000000))
用于对字符串的格式化
1.通过位置传递
print('{0}xxxxxxxx{1}'.format('这是0要传入的东西','这是1要传入的东西'))
2.通过关键字传递
print('{0}xxxxxxxx{1}'.format(0='xxx',1='xxx'))
如果是字典 print('{keys}xxxxxxxx{values}'.format(**<字典名>))
3.充当数字的千分位分隔符(例如:1,000,000)
print('{:,}'.format(1000000))
相关文章推荐
- python中format()函数的简单使用教程
- python3正则表达式简单使用、search()、match()等函数的区别
- Python: 字符串格式化format()函数的使用
- 简单介绍Python中的len()函数的使用
- python3正则表达式简单使用、search()、match()等函数的区别
- python字符串常量和使用format()函数格式化
- python使用第三方函数库及简单爬虫实验
- 简单介绍Python中的filter和lambda函数的使用
- Python(10)使用python函数实现一个简单的闭包操作
- Python学习21:Python中函数的用法,使用函数进行简单的数学运算
- javascript入门系列演示·函数的定义以及简单参数使用,调用函数 .txt
- Python中decorator的使用(@函数的使用)
- 通过 Python + Python Imaging Library (PIL) 生成简单函数图像
- Date && DateFormat && Calendar的简单使用
- 构建简单的 C++ 服务组件,第 2 部分: 通过服务组件体系结构使用 Python、Ruby 和 Web 服务
- [转] 最简单的使用UDP通信的Python Socket例子
- Python: 使用装饰器“@”取得函数执行时间
- python的日志简单使用
- LoadRunner lr_eval_string() 函数使用及LR中变量、参数的简单使用
- obstart() 几个函数的简单使用方法