第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

x,= ... - 這個(gè)尾隨逗號(hào)是逗號(hào)運(yùn)算符嗎?

x,= ... - 這個(gè)尾隨逗號(hào)是逗號(hào)運(yùn)算符嗎?

暮色呼如 2019-07-30 16:57:33
x,= ... - 這個(gè)尾隨逗號(hào)是逗號(hào)運(yùn)算符嗎?我不明白變量行后的逗號(hào)是什么,意思是:http://matplotlib.org/examples/animation/simple_anim.htmlline, = ax.plot(x, np.sin(x))如果我刪除逗號(hào)和變量“l(fā)ine”,變?yōu)樽兞俊發(fā)ine”,則程序被破壞。上面給出的url的完整代碼:import numpy as npimport matplotlib.pyplot as pltimport matplotlib.animation as animation fig = plt.figure()ax = fig.add_subplot(111)x = np.arange(0, 2*np.pi, 0.01)        # x-arrayline, = ax.plot(x, np.sin(x))def animate(i):     line.set_ydata(np.sin(x+i/10.0))  # update the data     return line,#Init only required for blitting to give a clean slate.def init():     line.set_ydata(np.ma.array(x, mask=True))     return line,ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,     interval=25, blit=True)plt.show()根據(jù)http://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences逗號(hào)后變量似乎與僅包含一個(gè)項(xiàng)目的元組有關(guān)。
查看完整描述

2 回答

?
隔江千里

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊

ax.plot()返回一個(gè)元組一個(gè)元件。通過將逗號(hào)添加到賦值目標(biāo)列表,您可以要求Python解包返回值并將其分配給依次命名為左側(cè)的每個(gè)變量。

大多數(shù)情況下,您會(huì)看到這適用于具有多個(gè)返回值的函數(shù):

base, ext = os.path.splitext(filename)

但是,左側(cè)可以包含任意數(shù)量的元素,并且只要是解包將發(fā)生的元組或變量列表。

在Python中,它是使逗號(hào)成為元組的逗號(hào):

>>> 11>>> 1,(1,)

在大多數(shù)位置,括號(hào)是可選的。您可以使用括號(hào)重寫原始代碼而不更改含義:

(line,) = ax.plot(x, np.sin(x))

或者您也可以使用列表語法:

[line] = ax.plot(x, np.sin(x))

或者,您可以將其重新編寫為使用元組解包的行:

line = ax.plot(x, np.sin(x))[0]

要么

lines = ax.plot(x, np.sin(x))def animate(i):
    lines[0].set_ydata(np.sin(x+i/10.0))  # update the data
    return lines#Init only required for blitting to give a clean slate.def init():
    lines[0].set_ydata(np.ma.array(x, mask=True))
    return lines

有關(guān)分配如何在解包方面工作的完整詳細(xì)信息,請(qǐng)參閱分配語句文檔。


查看完整回答
反對(duì) 回復(fù) 2019-07-30
?
aluckdog

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊

如果你有

x, = y

你解壓縮長度為一的列表或元組。例如

x, = [1]

會(huì)導(dǎo)致x == 1,而

x = [1]

給 x == [1]


查看完整回答
反對(duì) 回復(fù) 2019-07-30
  • 2 回答
  • 0 關(guān)注
  • 857 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)