Skip to content

Commit b03a3b2

Browse files
authored
Create func_arg.md
1 parent 772dc3e commit b03a3b2

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎CorePythonProgramming/func_arg.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
convert()函数传入一个内建函数int(),long(), 或者float()来执行转换:
2+
3+
```python
4+
#!/usr/bin/env python
5+
6+
def convert(func, seq):
7+
'conv. sequence of numbers to same type'
8+
return [func(eachNum) for eachNum in seq]
9+
10+
myseq = (123, 45.67, -6.2e8, 999999999L)
11+
print convert(int, myseq)
12+
print convert(long, myseq)
13+
print convert(float, myseq)
14+
```
15+
16+
输出:
17+
18+
[123, 45, -620000000, 999999999]
19+
[123L, 45L, -620000000L, 999999999L]
20+
[123.0, 45.670000000000002, -620000000.0, 999999999.0]

0 commit comments

Comments
 (0)