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

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.

主站蜘蛛池模板: 吉首市| 河曲县| 沧州市| 鄂伦春自治旗| 巢湖市| 泰州市| 台东县| 神农架林区| 平昌县| 乐清市| 湘乡市| 伽师县| 永修县| 金沙县| 陆良县| 文山县| 乐平市| 夏邑县| 常德市| 福海县| 浑源县| 西乌珠穆沁旗| 泽库县| 棋牌| 保德县| 邯郸县| 阿克| 玉田县| 靖州| 丰镇市| 连州市| 原阳县| 蒙阴县| 锡林郭勒盟| 原阳县| 五寨县| 宜川县| 南岸区| 东乌珠穆沁旗| 津南区| 云龙县|