(1) 数值运算 + - * / ,取余%
print(2+2)
print(3-2)
print(4*2)
print(6/2)
print(10%3) #输出 1
(2) 数据类型 int、float、str、bool
计算顺序:1.()2.[**] 3.* / 4.+ -
绝对值:abs()
四舍五入:round()
最大最小值:min(),max()
浮点数:1.3e5 即130000.0 ,0xFF 即255
num1=2
num2=3.22
str1='string'
print(type(num1) ) #输出int
print(type(float(num1))) #输出float ,值为2.0
print(3>5) #输出False
字符串操作
split(),join(),upper(),lower(),strip(),lstrip(),rstrip(),.format()
studystr='hello world'
print(studystr) #输出 hello world
study='hello'+'world'
print(study) #输出 helloworld
print(len(study)) #输出 9
print(studystr*3) #输出hello worldhello worldhello world
study='1 2 3 4 5'
study.split() #['1','2','3','4','5']
study1='1,2,3,4,5'
study1=study1.split(',')
print(study1) #['1','2','3','4','5']
study_str=' '
study_str.join(study1)
print(study_str) #'1 2 3 4 5'
study='hello world'
study.replace('world','python')
print(study) #hello python
study1=study
study1.upper() #HELLO PYTHON
study1.lower() #hello python
study2=' hello world '
study2.strip() #'hello world'暂时性修改
print(study2) #' hello world '
study2.lstrip() #'hello world '
study2.rstrip() #' hello world'
print('{} {} {}'.format('i','love','python'))
索引:从前面是0开始,从后面是-1开始
切片::表示从哪到哪,左闭右开的区间
study='hello world'
study[0] #'h'
study[6] #'w'
study[-1] #'d'
study[0:4] #'hell'
study[6:] #'world'
study[1:-2] #'ello wor'
通过 [ ]来创建一个list结构,里面放任何类型都可以,没有一个长度限制
pylist=[]
type(pylist) #list
pylist=[1,2,3,4]
pylist1=[1,2,'python',3.3]
pylist2=list([1,2,3])
print(pylist2) #[1,2,3]
#操作
len(pylist2) # 3
a=[123,456]
b=['aaa','bbb']
print(a+b) # [123,456,'aaa','bbb']
type(a+b) # list
a*3 # [123,456,123,456,123,456]
a[0] # 123
a[0:] #[123,456]
a[:]=['hello','python'] #直接赋值
a=[1,2,3,4,5,6,7]
a[3:5] #[4,5]
del a[3:] #[1,2,3] #直接删除
4 in a # False
a=[1,2,[3,4]]
a[2] # [3,4]
a[2][1] # 4
b=['q','w','w','s']
b.count(’w') # 2,统计个数
b.index('q') # 0,确定位置
#列表添加
c=[]
c.append('he') #['he']
c.append(['he','wo']) #['he',['he','wo'])
c.insert(2,'ld') #['he',['he','wo'],'ld']
c.remove(['he','wo']) # ['he','ld']
c.pop(1) #'ld'
print(c) ['he']
d=[1,2,3,6,5,6]
d.sort() # [1,2,3,5,6,6]
e=[1,2,3,9,6,3,2]
e1=sorted(e) #e1=[1, 2, 2, 3, 3, 6, 9],e不变
e.reverse() # [2,3,6,9,3,2,1]
key-value
pydict={}
type(pydict) # dict
py=dict()
type(py) #dict
pydict['first']=123
pydict['python']=456 # {'first': 123, 'python': 456}
pydict['python'] # 456
pydict['python']=789 #{'first': 123, 'python': 789} 直接修改值
dict_value=[1,2,3]
pydict={}
pydict['aa']=dict_value
pydict['bb']=3
pydict['cc']='4'
pydict # {'aa':[1,2,3],'bb':3,'cc':'4'}
dict={}
d1={'a':11,'b':22}
d2={'c':3,'d':4}
dict1['test1']=d1
dict1['test2']=d2
dict1 # {'test1':{'a':11,'b':22},'test2':{'c':3,'d':4}}
dict2=dict([('a',123),('b',456)])
dict2 # {'a':123,'b':456}
dict2['a'] +=1
dict2 # {'a':124,'b':456}
dict2.get('a') #124 获取对应key的value值
dict2.pop('a') #124
dict2 # {'b':456}
del dict2['b'] #{}
hello in dict2 # False
dict3= {'first': 123, 'python': 456}
dict3.keys() #dict_keys(['first','python'])
dict3.values() # dict_values([123,456])
dict3.items() # dict_items([('first',123),('python',456)])
会保留下来唯一的那些元素
pyset=[1,2,3,3,3]
pyset=set(pyset) # {1,2,3}
a={1,2,3,4}
b={2,3,4,5}
a.union(b) #{1,2,3,4,5}
a|b # {1,2,3,4,5}
a.intersection(b) #{2,3,4}
b.intersection(a) #{2,3,4}
a&b # {2,3,4}
a.difference(b) #{1}
b.difference(a) #{5}
a-b # {1}
b-a # {5}
a = {1,2,3,4,5,6}
b = {2,3,4}
b.issubset(a) #True
a.issubset(b) #False
b<=a #True
a<=a #True
a
aaa=1000
bbb=aaa
id(aaa) #2685260296752
id(bbb) #2685260296752
aaa is bbb #True
bbb=123456
id(bbb) #2685260297264 重新赋值后id值会变
aaa is bbb #False