python里的输入与输出

1.输入

输入函数:input(),默认输入的内容为字符。若要获取输入的数,则要进行类型转换。

使用eval(input())或int(input()),float(input())。

 

 2.输出:有多种输出方法

#方法一:使用字符相连

print('a'+repr(a)#str(a)+'的值')

#方法二:直接按位置输出

print('a的值为',a)

#方法三:使用占位符%

print('a的值为%d'%a)

#方法四:使用format格式化

print('a的值为{}'.format(a))

#方法五:使用f

print(f'a的值为{a}')


版权声明:本文为m0_54470017原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。