美文网首页
廖雪峰-输入与输出

廖雪峰-输入与输出

作者: harukou_ou | 来源:发表于2018-09-03 17:53 被阅读7次
>>> print('100 + 200 =', 100 + 200)
100 + 200 = 300
>>> name = input()
Michael
>>> name
'Michael'

因为input()返回的数据类型是str,str不能直接和整数比较,必须先把str转换成整数。Python提供了int()函数来完成这件事情:

设计程序实现以下结果:

C:\Workspace> python hello.py
please enter your name: Michael
hello, Michael

code:

name = input('please enter your name:')
print('hello,', name)

相关文章

网友评论

      本文标题:廖雪峰-输入与输出

      本文链接:https://www.haomeiwen.com/subject/lasiwftx.html