python学习
python学习资料参考
练习题
2.3 第一个程序
2.3.1
输入名字x,利用print 语句:“Hello,x, how are you”,例如x为Xiaoming, 输出”Hello, Xiaoming, how are you”
x=input()
print('Hello,',x,'how are you')
报警处理
C:\Master\python>python hello.py
Please input your name:d
Traceback (most recent call last):
File "hello.py", line 2, in <module>
x=input('Please input your name:')
File "<string>", line 1, in <module>
NameError: name 'd' is not defined
C:\Master\python>python3 hello.py
di
Hello, di how are you
python版本问题 安装了python2和python3两个版本 python默认为python2
同时安装python2和python3见
python2和python3共存
3.1 数据类型和变量量
3.1.1
输入整形值x,输出x的平方和x的立方。例如输入2,输出4和8.
x=input()
print(x*x,x*x*x)
错误报警
Traceback (most recent call last): File "hello.py", line 6, in <module> print(x*x,x*x*x) TypeError: can't multiply sequence by non-int of type 'str'
python3 里面将input返回的默认为str类型