python,如何建立一系列函数,用数组和循环可以吗?
答案:2 悬赏:30 手机版
解决时间 2021-02-15 17:31
- 提问者网友:最爱你的唇
- 2021-02-14 23:13
python,如何建立一系列函数,用数组和循环可以吗?
最佳答案
- 五星知识达人网友:人间朝暮
- 2021-02-14 23:39
IPython 2.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: flows=[]
In [2]: for i in range(10):
...: def foo(a):
...: def _():
...: print a
...: return _
...: flows.append(foo(i))
...:
In [3]: for foo in flows:
...: foo()
...:
0
1
2
3
4
5
6
7
8
9
In [4]:
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: flows=[]
In [2]: for i in range(10):
...: def foo(a):
...: def _():
...: print a
...: return _
...: flows.append(foo(i))
...:
In [3]: for foo in flows:
...: foo()
...:
0
1
2
3
4
5
6
7
8
9
In [4]:
全部回答
- 1楼网友:罪歌
- 2021-02-15 00:04
''.join(
map(str, intserial)
)''.join( # 将后面的字符串列表用 '' 拼接起来;
map(str, intserial) # 将intserial中的每个变量用str函数转换成字符串的列表
$ python
python 2.7.3 (default, mar 14 2014, 11:57:14)
[gcc 4.7.2] on linux2
type "help", "copyright", "credits" or "license" for more information.
>>> intserial=range(15)
>>> intserial
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
>>> ''.join(
... map(str, intserial)
... )
'012345678910
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯