1.求最大值,最小值
(1)最小值
In [55]: min(2,3)
Out[55]: 2
(2)最大值
In [56]: max(2,3)
Out[56]: 3
2.求和
(1)1-100求和
In [57]: sum(range(1,101))
Out[57]: 5050
(2)1-100的奇数求和
In [58]: sum(range(1,101,2))
Out[58]: 2500
(3)1-100的偶数求和
In [59]: sum(range(2,101,2))
Out[59]: 2550
3.枚举:返回索引值和对应的value值
for i,v in enumerate('hello'):
print(i,v)
测试结果:
0 h
1 e
2 l
3 l
4 o
4.zip
s1 = 'abc'
s2 = '123'
for i in zip(s1,s2):
print(i)
测试结果:
('a', '1')
('b', '2')
('c', '3')
2>
for i in zip(s1,s2):
print(''.join(i))
print('-'.join(i))
测试结果:
a1
b2
c3
a-1
b-2
c-3