2019/11/02 今日小结

现在如果你写一个程序与用户交互

输入

python2:input一定要声明你输入的类型

input(“》》:”)

》》:sean

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'sean' is not defined

>>> input(">>:")

>>:"sean"

"sean”

>>>raw_input(">>")

>>:sean

“Sean”

>>>raw_input(">>:")

>>:12

"12"

python3:

name = input("请输入您的名字;")     #接收用户的输入,无论用户输入的是什么类型

print(name)

print(type(name))

print(name)

总结:

python2中的raw_input与python3中input作用相同

2、基本数据类型

数据:描述、衡量数据的状态

类型:不同的事物需要不同的类型存储

int

python2:分为整型和长整型  如果在合格范围内,就是int

如果不在这个区间,就是long长整型

python3:int

folat:浮点型

str

python2:

str本质就是8个bit位的序列

python3:

str本质就是Unicode的序列

list

dict

bool

3、格式化输出

1、%s   %d

%s   可以接受任意类型的变量

%d   只能接受数字类型的变量

“my name is xxx,my age is xxx”

print("my name is %s,my age is %s”%(name,age))

原文地址:https://www.cnblogs.com/medigrat/p/11783474.html