美文网首页
python——数据类型

python——数据类型

作者: ELLENXX | 来源:发表于2019-06-28 19:56 被阅读0次

类型

  • 整数int()
  • 字符串str()
  • 浮点数float()

dome

b=str(678)
c=int(22.98)
d=str(22.98)
e=int('242')
f=float('242')
print(a,b,c,d,e,f)

结果:
678.0 678 22 22.98 242 242.0

如果

str='the name of variable is str'
print(str)

发现没有报错,还是可以输出the name of variable is str
但是之后再使用str()

str='the name of variable is str'
a=str(33)
print(str)
image.png

这是因为:str是一个内置函数,你可以自己给str赋予新身份,就比如是一个变量,这个新身份将会代替str原来的作用,之后再用str就只是一个变量了。

type()函数

可以告诉我们数据类型

a=type(True)
print(a)

输出:<class 'bool'>

isinstance()

可以告诉我们值与数据类型是否一样,一样返回True,否则返回False

x=isinstance(888,int)
y=isinstance(3.2,int)
z=isinstance(True,bool)

输出:True False True

相关文章

网友评论

      本文标题:python——数据类型

      本文链接:https://www.haomeiwen.com/subject/qztycctx.html