常用函数
print(2+1)
print(2-1)
print(3*1)
print(3/1)
3.0 /
_
print(2**3)
print(10%3)
print(10/3)
:
e
列表
s=[‘a’,’b’,’c’,’d’]
print(s)
print(len(s))
print(type(s))
:
s=[‘a’,’b’,’c’,’d’]
print(s[2])
print(s[-2])
:
正序-1
s=[‘a’,’b’,’c’,’d’]
print(s[0:4])
print(s[1:3])
print(s[1:])
print(s[:3])
:列表
省略:开头,结尾
s=[‘a’,’b’,’c’,’d’]
s.append(‘e’)
print(s[4])
o
字典
d={‘qq’:[‘1’,’2’,’3’],456:[‘a’,’b’,’c’],’j’:100}
a1=d[‘qq’]
b1=a1[0]
print(b1)
d={‘qq’:[‘1’,’2’,’3’],456:[‘a’,’b’,’c’],’j’:100}
print(d[456])
print(d[456][1])
d={‘qq’:[‘1’,’2’,’3’],456:[‘a’,’b’,’c’],’j’:100}
print(d[‘j’])
d[‘j’]=900
print(d[‘j’])
d={‘qq’:[‘1’,’2’,’3’],456:[‘a’,’b’,’c’],’j’:100}
print(d)
d[89]=’r’
print(d)
新增
2
for
:
冒号+
for i in[1,2,3]:
print(i)
for i in{1:1,2:2,3:3}:
print(i)
字典
字符串
a=10
b=3.14
c=’hh’
print(‘n%dm’%a)
a=10
b=3.14
c=’hh’
print(‘n%fm’%b)
a=10
b=3.14
c=’hh’
print(‘n%sm’%c)
a=10
b=3.14
c=’hh’
print(‘n,%d,or%f+%sm’%(a,b,c))
+
换行,上限