Python数据类型-布尔/数字/字符串/列表/元组/字典/集合

时间:2022-02-24 04:29:34

代码

bol     = True                  # 布尔
num     = 100000000;            # 数字
str     = "fangbei";            # 字符串
str_cn  = u"你好,方倍";        # 字符串 中文unicode
list    = [1, 2, 3, 3, 'fangbei'];                  # 列表,方括号,可重复,元素类型可不同
tuple   = (');  # 元组,小括号,和列表相似,但内容不可修改!
dict    = {'name': "fangbei", 'age': 28};           # 字典,大括号,存储键值对,类似json
set     = set(['fang', 'bei', 'm']);                # 集合,用于去重

print (type(bol));
print (type(num));
print (type(str));
print (type(str_cn));
print (type(list));
print (type(tuple));
print (type(dict));
print (type(set));

返回

<class 'bool'>
<class 'int'>
<class 'str'>
<class 'str'>
<class 'list'>
<class 'tuple'>
<class 'dict'>
<class 'set'>