官术网_书友最值得收藏!

List types

Python does not have array types, but instead offers the list data type. Python lists also fall under the category of sequences and offer a wide range of functionalities. Coming from a Java, C, or C++ background, you are likely to find that Python lists are slightly different from the arrays and list types offered by these languages. In C, C++, or Java, an array is a collection of elements of similar data types, and this is also the case for Java array lists. This is different in the case of Python. In Python, a list is a collection of elements that can be of either homogeneous and heterogeneous data types. This is one of the features that makes Python lists powerful, robust, and easy to use. We also don't need to specify the size of a Python list when declaring it. It can grow dynamically to match the number of elements it contains. Let's see a basic example of using lists:

Lists in Python start from index 0 and any item can be accessed on the basis of indices, as shown in the preceding screenshot. The preceding list is homogeneous, as all the elements are of string type. We can also have a heterogeneous list, as follows:

For now, we are printing the list elements manually. We can very easily iterate over them with loops instead, and we will explore that later on. For now, let's try to understand which operations can be performed on list structures in Python.

主站蜘蛛池模板: 商南县| 黎平县| 鹿邑县| 福贡县| 越西县| 开原市| 庆安县| 凤阳县| 泰和县| 定襄县| 临猗县| 冀州市| 图片| 三都| 古蔺县| 丹江口市| 梓潼县| 理塘县| 拜城县| 会理县| 桃源县| 榆林市| 蒙阴县| 玛沁县| 高邮市| 广州市| 石柱| 温州市| 洪雅县| 陇西县| 奇台县| 新河县| 辽宁省| 霍邱县| 武平县| 沅陵县| 醴陵市| 潼南县| 海原县| 美姑县| 荆州市|