# encoding: utf-8
"""
@author: lanxiaofang
@contact: fang@lanxf.cn
@software: PyCharm
@file: 03_0204_basedatatype.py
@time: 2020/2/4 17:33
"""


# 定义列表

# lista = [1, 2, 3, 4, 5]
# listb = ["Hello word", 1, True, False]
# listc = ["Hello word", [1, "Hello", [2, "word"]]] # 嵌套列表
# print(type(lista), type(listb), type(listc))


# 访问列表元素

# listd = ["李白", "杜甫", "陆游", "王安石"]
# liste = ["贺知章", "李清照", "曹操", "曹植", "李密", "白居易"]
# print(listd[0], listd[-1], listd[0:2], listd[-1:], listd[-3:-1]) # 对0和-1的取值所输出的内容不太理解的可以好好分析这一段输出
# # 列表中的 + 和 * , 没有 -
# listf = listd + liste # 在listd的内容中追加内容liste
# print(listf)
# listg = listd * 3 # 将listd中的内容重复3次
# print(listg)
# print(listf - liste) # 此行输出会报错 TypeError: unsupported operand type(s) for - :


# 嵌套列表

listh = [["刘禹锡", "韦应物", "李商隐", "杜牧"], ["韩愈", "孟浩然"], [], {1, 2}, (1, 2), {'name': 'named'}]
# print(listh[0], listh[1:3])


# 元组的定义
tuple1 = (1, 2, 3, 4)
# print(type(tuple1), tuple1)
list1 = [7, 8, 9, tuple1]
tuple2 = (1, "China", "HuNan", tuple1, list1)
# print(type(tuple2), tuple2)
# 元组内容的获取
# print(tuple1[0], tuple2[0:2])
# 元组中的 + *
# tuple3 = tuple1 + tuple2
# tuple4 = tuple1 * 2
# print(tuple3)
# print(tuple4)

#当元组Tuple中只有一个元素的时候,
# tuple5 = (1)
# tuple6 = ("Hello")
# 则执行的时候()的优先级会高一些,因此输出的结果是对应元组内容的类型
# print(type(tuple5), type(tuple6))
# 如果想要输出的类型是tuple则需要在这单个元素后加个,
# tuple7 = (1,)
# tuple8 = ("hello",)
# print(type(tuple7), type(tuple8))
# 表示一个空的元组
# tuple9 = ()
# print(type(tuple9))


# str list tuple 序列,序列中的元素是有序的,都有一个序号
# 切片的用法 [a:b] [a:b:c]

# 如何判断一个元素是否存在一个序列中 在 in 不在 not in
list1 = [1, 2, 3]
list2 = [list1, 4, 5]
str1 = "Hello, word!"
tuple10 = ("A", 'B')
tuple11 = (list1, 6, "789", (tuple10, 'C'), {'name': 'lxf'}, {1, 2}, tuple10, True)
# print(3 in list1)
# print(4 not in list1)
# print(list1 in tuple11)
# print(tuple10 in tuple11)
# print(tuple10 in tuple11[3])
# 序列的元素个数 len
# print(len(list1))
# print(len(str1))
# print(len(tuple10), len(tuple11))
# 序列中的最大值max() 最小值min()
# print(max(list1), min(list1))
# print(max(str1), min(str1))
# print(max(tuple10), min(tuple10))
# print(max(list2)) # 报错 TypeError: '>' not supported between instances of 'int' and 'list'
# print(max(tuple11[0]), min(tuple11[3])) # 报错 TypeError: '<' not supported between instances of 'str' and 'tuple'
# print(max('a', 'A'))
# print(min('Hello word'), min('Helloword')) # 这一行的第一个的输出是空格
# ASCII码 ord()
# print(ord(' '), ord('H'))


# 集合set 无序 不重复(单一)
set1 = {1, 2, 3, '打豆豆'}
set2 = {1, 1, 2, 2, 3, 4, 5, 6}
set21 = {1, 2, (1, 2)}
# set22 = {1, 2, [1, 2]} # 报错TypeError: unhashable type: 'list'
# set23 = {1, 2, 3, '打豆豆', {'name': 'lll'}} # 报错 TypeError: unhashable type: 'dict'
# set3 = {set1, set2, 5, 6} # 报错 TypeError: unhashable type: 'set'
# print(type(set1))
# print(set2) # 不重复(单一)

# 集合的长度
# print(len(set1), len(set2))

# 判断某元素是否在集合中 in not in
# print(1 in set1, 4 not in set1)
# print(set1 in set2)

# # 求两个集合的差值 -
# print(set2 - set1)
# # 求两个集合的和集 | ,自动去重
# print(set1 | set2)
# #求两个集合的并集 &
# print(set1 & set2)

# 定义一个空的集合
# set4 = set()
# print(len(set4))


# 字典 dict {Key: Value}
# 也是一个集合,有序,但不是序列
# 字典的定义方式 嵌套字典
dictmine = {
'name': '懒笑翻',
1: 1,
'age': 99,
'tel': {'1321266', 9837702},
'addr': {
'HuNan': 'Changsha',
'HuBei': 'Beijing'
}
}
# 字典的访问
# 通过key访问value
# print(dictmine['name'])
# print(dictmine['addr'])
# print(dictmine['addr']['HuNan'])
# 字典的key不一定是字符串类型,也可以是数字类型 1 和 '1'是不同的
dictmine2 = {
'name': '懒笑翻',
1: 1,
'1': '1'
}
# print(type(dictmine2))
# print(dictmine2[1],dictmine2['1'])

# 字典中的 key 必须是不可变的类型 比如可以是int,'str' , tuple 不可以是List, set ,dict 但可以是Tuple
dicttest = {
1: 'Hello',
'name': '懒笑翻',
# [1, 2]: 'Happy', # 报错 TypeError: unhashable type: 'list'
# {1, 2}: 'set', # 报错 TypeError: unhashable type: 'set'
# {'test': 'test'}: 'dict', # 报错 TypeError: unhashable type: 'dict'
(1, 2): (1, 2, 3),
'lista': [1, 2, 3],
False: '0',
True: '1',
35j: '35j',
35.2: '35.2',

}
# print(dicttest[(1, 2)])
# 空字典的定义
# dictnull = {}
# print(type(dictnull))