005闲聊之python的数据类型

“520” 和 520

>>> 520 + 1314
1834
>>> "520" + "1314"
'5201314'
>>> 
  1. 整型和浮点型的区别,有没有小数点
  2. 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

课后作业

  1. 写一个程序,判断给定年份是否为闰年
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 + "不是闰年")
发布了42 篇原创文章 · 获赞 0 · 访问量 301

猜你喜欢

转载自blog.csdn.net/qq_43169516/article/details/103120824