温馨提示×

python怎么打印list的大小

小亿
86
2024-06-11 18:00:41
栏目: 编程语言

在Python中,你可以使用内置的`len()`函数来获取列表(list)的大小(即元素的数量),然后使用`print()`函数来打印这个大小。下面是一个简单的示例:

```python

my_list = [1, 2, 3, 4, 5]

list_size = len(my_list)

print("The size of the list is:", list_size)

```

当你运行这段代码时,它会输出:

```csharp

The size of the list is: 5

```

在这个例子中,`len(my_list)`返回列表`my_list`的元素数量,即5,然后`print()`函数将这个值打印出来。

0