print(f'1+1={2}')
#输出:1+1 = 2
a=1+1
print(f'1+1={a}')
#输出:1+1 = 2
print(f'1+1={1+1}')
#输出:1+1 = 2
importmath
a=8
print(f'{math.log(8)=}')
#输出:math.log(8)= 2.0794415416798357
a=1
b=2
c=3
s=(
f'{a=}\n'
f'{b=}\n'
f'{c=}\n'
)
print(s)
#输出:
a=1
b=2
c=3
importmath
pi=math.pi
print(f'{pi:.3f}')
print(f'{pi:.8f}')
#输出
3.142
3.14159265
number_10=1024
print(f'{number_10:b}')#2进制
print(f'{number_10:o}')#8进制
print(f'{number_10:x}')#16进制小写
print(f'{number_10:X}')#16进制大写
print(f'{number_10:c}')#ASCII编码
#输出:
10000000000
2000
400
400
text='python'
print(f'{text:>10}')#右对齐
print(f'{text:<10}')#左对齐
print(f'{text:^10}')#居中对齐
print(f'{text:*^10}')#居中对齐,用*补齐空白
n=10
print(f'{text:#^{n}}')#参数嵌套,居中对齐,用~补齐空白
#输出:
python
python
python
**python**
##python##
forxinrange(1,11):
print(f'{x:02}|{x**2:3}/{x**5:6}')
#输出:
01|1|1
02|4|32
03|9|243
04|16|1024
05|25|3125
06|36|7776
07|49|16807
08|64|32768
09|81|59049
10|100|100000
importdatetime
now=datetime.datetime.now()
print(f'{now:%Y年%m月%d号%H点%M分%S秒}')
#输出:
2022年05月21号17点04分08秒
importmath
pi=math.pi
print(f'{pi*100:.10e}' )
#输出
3.1415926536e+02
a=1312.3123123123123
print(f'{a:.10g}')
#输出:1312.312312
a=1312.3123123123123
print(f'{a:.3g}')
#输出:1.31e+03
分享
点收藏
点点赞
点在看
文章转发自AI科技大本营微信公众号,版权归其所有。文章内容不代表本站立场和任何投资暗示。
Copyright © 2021.Company 元宇宙YITB.COM All rights reserved.元宇宙YITB.COM