简体   繁体   English

双方括号可变

[英]Double square brackets with variable

I am rather new to python. 我是python的新手。 I have come across colleagues' code 我遇到过同事的密码

def calc(lst):
    lst = [[some_var]]

What does it mean? 这是什么意思? I guess it's a double-dimensional array, but nothing more is coming to my mind 我想这是一个二维数组,但我想不起

Thank you in advance 先感谢您

Variable points to a nested list, where length of outer as well as inner list is 1. 变量指向嵌套列表,外部列表和内部列表的长度均为1。

In [9]: lst = [[1]]

In [10]: len(lst)
Out[10]: 1

In [11]: len(lst[0])
Out[11]: 1

Appending list to an empty list, 将清单附加到空白清单,

In [12]: lst = []

In [13]: lst.append([1])

In [14]: lst
Out[14]: [[1]]

It depends on what data type some_var is holding. 这取决于some_var持有哪种数据类型。 If some_var is a primitive data type, say integer, then lst is a list of list of an integer. 如果some_var是原始数据类型,例如整数,则lst是整数列表的列表。 But if some_var is a list itself, then lst is a list of list of list 但是如果some_var本身是一个列表,则lst是list的列表list

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM