python控制输入输出格式及进制转换问题

1. 输入

整形输入

a = int(input())

浮点输入

b = float(input())

输入三个数

a,b,c = map(int,input().split())

输入一串数字

list1 = list(map(int,input().split()))
list2 = [int(i) for i in input().split()]

2. 输出

隔空输出

list1 = [1,2,3,4]
print(' '.join(map(str,list1)))

四舍五入

print(int(0.56 + 0.5))
print(int(0.46+0.5))

保留两位

a = 456464.20132 
print("%.2f"%a)

使用字符串进行格式化输出

print('{0:d},{1:o},{3:x},{2:b}'.format(255,255,255,255))
255,377,ff,11111111
print("%d,%o,%x,%X"%(255,255,255,255))
255,377,ff,FF

format 参考链接:https://www.runoob.com/python/att-string-format.html

字符串格式化输出%: https://www.cnblogs.com/nowgood/p/str_formatter01.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值