4、python常用基础类型介绍

1、字符串 str

描述性质的一种表示状态的例如名字

word='helloworld'

print(type(word),word)
  <class 'str'> helloworld
2、列表类型 list

存储多个值

l=[1,2,3,4]
print(type(1),l)
  <class 'int'> [1, 2, 3, 4]
3、元祖类型 tuple

存多个值。和列表的区别在于,列表的内容可以变化。但是元祖不可变(后面会说到这个)

t=(1,2,3,4)
print(type(t),t)  
  <class 'tuple'> (1, 2, 3, 4)
4、字典类型 dict

存多个值,且单个值得为key:value的成组出现

dic={"a":1,'b':2}
print(type(dic),dic)
  <class 'dict'> {'a': 1, 'b': 2}
5、bool类型

多数用于判断

 

在所有的bool值得类型中,只有两个答案,True (真)、 False(假)

a=1
b=2
print(a < b)
  True
print(a > b)
  False

6、整形及其浮点型

表示大小,多数用于数值比较

a=123
print(a,type(a))
b=1.2
print(b,type(b))
123 <class 'int'>
1.2 <class 'float'>

posted @ 2018-06-11 15:28  骑猪追夕阳_577513827  阅读(107)  评论(0编辑  收藏  举报