python的输入输出格式

1.输入格式

(1)直接输入

raw_input('提示词')

(2)将输入的值赋值给passwd

passwd = raw_input('请输入你的密码:')

(3)将输入的值转换类型赋值给price

price = float(raw_input('水果的单价:'))

2.输出格式

(1)print '格式化字符串' % 变量1

print '你的密码为 %d '  %password

扫描二维码关注公众号,回复: 2992581 查看本文章


(2)print '格式化字符串' %(变量1,变量2)
print '水果的单价为 %.2f 您购买了 %.2f 总价格为 %.3f '%(price,weight,money)

(3)格式化字符串含义
%s   字符串str
%f   float类型 %.2f 输出小数点后两位 %.0f 小数点后输出0位
%d   整型 %06d不到6位就补0,是6位或超过6位,该多少就显示多少
%%   输出%

猜你喜欢

转载自blog.csdn.net/qq_42224396/article/details/82084479