python3.6使用f-string来格式化字符串,,这里的f-strin
python3.6使用f-string来格式化字符串,,这里的f-strin
这里的f-string指的是以f或F修饰的字符串,在字符串中使用{}来替换变量,表达式和支持各种格式的输出。详细的格式化定义可以看官方文档
>>> a, b = 30, 20>>> print(f"the result of 30 - 20 is {a - b}")the result of 30 - 20 is 10>>> import datetime>>> print(f"now is {datetime.datetime.today()}")now is 2019-03-14 00:49:44.853937>>> name = "Fred">>> f"He said his name is {name!r}.""He said his name is 'Fred'.">>> f"He said his name is {repr(name)}." # repr() is equivalent to !r"He said his name is 'Fred'.">>> width = 10>>> precision = 4>>> value = decimal.Decimal("12.34567")>>> f"result: {value:{width}.{precision}}" # nested fields'result: 12.35'>>> today = datetime(year=2017, month=1, day=27)>>> f"{today:%B %d, %Y}" # using date format specifier'January 27, 2017'>>> number = 1024>>> f"{number:#0x}" # using integer format specifier'0x400'
python3.6使用f-string来格式化字符串
相关内容
- 使用python已知平均数求随机数,,问题描述:产生40个
- Python真的什么都可以做,胶水语言可不是白叫的,,作为
- 通过python调用adb命令对app进行测试 启动/停止app,,转于
- python 高级一点的用法,猴子补丁与元类,,好久没更新了
- python2系列 接入阿里云oss sdk 实现上传脚本,亲测,,公
- python简单的while语句和if语句的练习,,允许用户登录三
- python函数递归-实例,,1.在一个函数体内调
- python进行des加密解密,而且可以与JAVA进行互相加密解密
- python3多线程和GIL全局解释器所,,#线程的并发是利用
- python基础01,,1、python介绍
评论关闭