“520” 和 520
>>> 520 + 1314
1834
>>> "520" + "1314"
'5201314'
>>>
- 整型和浮点型的区别,有没有小数点
- e记法表示很大或者很小的数
>>> 15e10
150000000000.0
int用法(整数integer)
直接把小数点后面砍掉
>>> int(5.99)
5
float用法(浮点数)
多出一个小数点
>>> float(520)
520.0
str用法(string字符串)
>>> str(520)
'520'
>>> str(5e10)
'50000000000.0'
>>>
type函数(相当于找到他的族类型)
>>> type(520)
<class 'int'>
>>> type(5e15)
<class 'float'>
isinstance举例判断(判断他是不是属于这个族类型)
>>> isinstance(5,str)
False
>>> isinstance(5,int)
True
>>> isinstance(5e3,str)
False
>>> isinstance(5e3,int)
False
>>> isinstance(5e3,float)
True
>>> isinstance("我我我",str)
True
课后作业
- 写一个程序,判断给定年份是否为闰年
temp = input("请输入一个年份:")
while not temp.isdigit:
temp = input("对不起,请输入一个整数:")
year = int(temp)
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
print (temp + "是闰年")
else:
print(temp + "不是闰年")