亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 3996 | 回復: 4
打印 上一主題 下一主題

python的*args是什么意思? [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2012-06-03 08:59 |只看該作者 |倒序瀏覽
  1. from itertools import izip_longest
  2. def grouper(n, iterable, fillvalue=None):
  3.     "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
  4.     args = [iter(iterable)] * n
  5.     return izip_longest(fillvalue=fillvalue, *args)
  6. for i in grouper(3,'ABCEDFG','x'): print i

復制代碼
windows系統(tǒng)python2.7自帶文檔庫函數(shù)手冊中,有這樣一個例子。

請問*args是怎么用的? izip_longest的參數(shù)一般有兩個,一個是迭代對象(iterable),另一個是填充(filvalue)。為什么在這個例子中,參數(shù)卻是fillvalue和*args。

另外,某天有朋友問: 如何把列表3個3個地分組?     這兒似乎對這個問題提供了一種別樣的解答。

論壇徽章:
2
CU大;照
日期:2013-04-17 11:46:28CU大牛徽章
日期:2013-04-17 11:46:39
2 [報告]
發(fā)表于 2012-06-03 10:07 |只看該作者
貌似指明為元組

論壇徽章:
0
3 [報告]
發(fā)表于 2012-06-03 15:58 |只看該作者
本帖最后由 niexining 于 2012-06-03 16:00 編輯
  1. ('A', 'B', 'C')
  2. ('E', 'D', 'F')
  3. ('G', 'x', 'x')
復制代碼
這是運行結(jié)果.


是不是放了3個迭代器進去, 就3個字符3個字符地迭代?

論壇徽章:
0
4 [報告]
發(fā)表于 2012-06-03 16:17 |只看該作者
4.7.4. Unpacking Argument Lists
The reverse situation occurs when the arguments are already in a list or tuple but need to be unpacked for a function call requiring separate positional arguments. For instance, the built-in range() function expects separate start and stop arguments. If they are not available separately, write the function call with the *-operator to unpack the arguments out of a list or tuple:

>>>
>>> range(3, 6)             # normal call with separate arguments
[3, 4, 5]
>>> args = [3, 6]
>>> range(*args)            # call with arguments unpacked from a list
[3, 4, 5]
In the same fashion, dictionaries can deliver keyword arguments with the **-operator:

>>>
>>> def parrot(voltage, state='a stiff', action='voom'):
...     print "-- This parrot wouldn't", action,
...     print "if you put", voltage, "volts through it.",
...     print "E's", state, "!"
...
>>> d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"}
>>> parrot(**d)
-- This parrot wouldn't VOOM if you put four million volts through it. E's bleedin' demised !
                           

論壇徽章:
0
5 [報告]
發(fā)表于 2012-06-05 16:37 |只看該作者
回復 4# anonymous0502

這個兩個例子很好.   剩下的就是關(guān)于迭代器的還太理解.

   
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP