W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
Python compile() 函數(shù)將一個(gè)字符串編譯為字節(jié)代碼。
以下是 compile() 方法的語(yǔ)法:
compile(source, filename, mode[, flags[, dont_inherit]])
返回表達(dá)式執(zhí)行結(jié)果。
以下展示了使用 compile 函數(shù)的實(shí)例:
>>>str = "for i in range(0,10): print(i)"
>>> c = compile(str,'','exec') # 編譯為字節(jié)代碼對(duì)象
>>> c
<code object <module> at 0x10141e0b0, file "", line 1>
>>> exec(c)
0
1
2
3
4
5
6
7
8
9
>>> str = "3 * 4 + 5"
>>> a = compile(str,'','eval')
>>> eval(a)
17
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: