當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python ast.List用法及代碼示例

用法:

class ast.List(elts, ctx)
class ast.Tuple(elts, ctx)

列表或元組。 elts 保存代表元素的節點列表。如果容器是分配目標(即 (x,y)=something ),則 ctxStore,否則為 Load

>>> print(ast.dump(ast.parse('[1, 2, 3]', mode='eval'), indent=4))
Expression(
    body=List(
        elts=[
            Constant(value=1),
            Constant(value=2),
            Constant(value=3)],
        ctx=Load()))
>>> print(ast.dump(ast.parse('(1, 2, 3)', mode='eval'), indent=4))
Expression(
    body=Tuple(
        elts=[
            Constant(value=1),
            Constant(value=2),
            Constant(value=3)],
        ctx=Load()))

相關用法


注:本文由純淨天空篩選整理自python.org大神的英文原創作品 ast.List。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。