当前学习版本为: python-3.6-4
代码:
"""整型 NUMBER"""
a = 2 ** 5
b = a + 4
c = a / 4
d = a // 4
e = a % 5
f,g = 120,112
h = 3 + 4j
i = 4 + 8j
j = h * i
print(a,b,c,d,e,f,g,j) """字符串型String"""
str = 'wo shi zhang san!'
#str[0] = '1' #字符串单个字符不可被修改
print(str[0:-3])
print(str[0:1])
print(str[1:5]) #输出下标为1至下标为4的字符子串,即第二个至第五个的字符子串
print(str * 4)
print(str + str ) """"列表型list"""
list = ["zhangsan","lisi","wangwu","zhaoliu","zhouqi"]
list[4] = "xiaozhe" #元素可以被修改
print(list)
print(list[0:3])
print(list + list) """tuple 元组型"""
#ple = ("1",'2')
tuple = ( 1,2,3,4,5,6,7)
#tuple[4] = 44 #元素不可以被修改否则报错
etuple = () #空元组
otuple = (1) #单元素元组 print(tuple[0:2])
print(tuple * 3)
print(etuple)
print(otuple) """set集合型"""
set1 = {"zhangsan","lisi", "wangwu", 'lisi', "小七"}
#per = set("nishi","woshi","tashi") #创建一个新的集合
per = set("nishi") #创建一个新的集合
print(set1,per)
a = set('abracadabra')
b = set('alacazam') print("set-a =",a)
print("set-b =",b) print("a - b =",a - b) # a和b的差集 print("a | b =",a | b) # a和b的并集 print("a & b =",a & b) # a和b的交集 print("a ^ b =",a ^ b) # a和b中不同时存在的元素 """字典型"""
#键值对的形式存储,类似Json个是中键值的表示
dict = {} #必须步骤声明为一个字典类型
dict[""] = "c++"
dict[""] = "java"
dict[""] = "c"
dict[""] = "python"
print(dict)
print(dict[""])
print(dict.keys())
print(dict.values())
结果: