这是什么[:]在Python意思 [英] What does [:] in Python mean

查看:105
本文介绍了这是什么[:]在Python意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我分析一些Python code,我不知道是什么

I'm analyzing some Python code and I don't know what

pop = population[:]

表示。它是在Java或像双维数组像数组列表?
莫非AP preciate一些帮助,谢谢。

means. Is it something like array lists in Java or like a bi-dimensional array? Could appreciate some help, thanks.

推荐答案

这是一个切片,和它做什么取决于人口的类型。如果人口是一个列表,这条线将创建列表的副本。对于类型的对象元组 STR ,它不会做任何事情(行会做同样的无 [:] ),并为(比如说)numpy的阵列,它会创建到同一个数据的新视图

It's a slicing, and what it does depends on the type of population. If population is a list, this line will create a copy of the list. For an object of type tuple or a str, it will do nothing (the line will do the same without [:]), and for a (say) NumPy array, it will create a new view to the same data.

这篇关于这是什么[:]在Python意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆