L2.六.判断变量类型

#  判断变量类型  
# 类型不同,input() 用户输入 返回的是字符串
# '1' + 3 '小明考了' + 90 报错


# type() 判断变量类型
a = 1
b = 1.5
c = 'hello word'
d = True
type(a) #<class 'int'>
type(b) #<class 'float'>
type(c) #<class 'str'>
type(d) #<class 'bool'>

# score = input('请输入成绩:')
# isinstance(值, 类型)
如果值属于类型的话返回True
isinstance(1, int) # True
isinstance(1, float) # False
isinstance('小明', float) #False
posted @ 2018-10-24 20:37  pypi111258  阅读(91)  评论(0编辑  收藏  举报