python学习笔记整理----输入、输出与数值类型

python输入与输出

python的输出

python2 : print “要打印的字符串”

python3 : print (“要打印的字符串”)

python的输入

python2 :
raw_input() : 接受字符串的数据;
input() : 只能接受数值类型;

# python2的操作
# name = raw_input("input name:")
# print name
#
# info = input("input:")
# print info

python3:
没有raw_input,只有input,
python3中为了避免记忆困难,用input接受数据,为字符串类型;

name = input("Name:")
print(name)
age = input("Age:")
print(age,type(age))

print "%s" %(001)
1
print "%d" %(001)
1
# 八进制转化为十进制
print "%d" %(0011)
9
# 十进制转化为八进制
print "%o" %(9)
11
print "%o" %(10)
12
print "%o" %(11)
13
# 十六进制转化为十进制
print "%x" %(16)
10
print "%x" %(17)
11
print "%x" %(11)
b
# 浮点数
print "%f" %(11)
11.000000
# 保留三位小数
print "%.3f" %(11)
11.000
print "%.2f" %(11)
11.00

# 要想输出%,要使用两个%。进行转义
print "内存占有率:%.2f%%" %(1.23324546456)
内存占有率:1.23%
python中支持的数据类型:int long float complex

python3中去掉了long

数据类型的转换:在python中,所有的数据类型。都可以作为内置函数,转换数据类型;
删除内存中的变量,可使用del

猜你喜欢

转载自blog.csdn.net/qq_41891803/article/details/81408116
今日推荐