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

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.

主站蜘蛛池模板: 湛江市| 庆城县| 道孚县| 高淳县| 抚宁县| 长葛市| 白朗县| 明水县| 新余市| 濮阳县| 通渭县| 游戏| 吉木萨尔县| 江津市| 扎赉特旗| 内乡县| 宿州市| 玉山县| 定结县| 凯里市| 东山县| 通州区| 浦县| 沈阳市| 开阳县| 铁岭市| 石屏县| 兖州市| 扎赉特旗| 阜康市| 定兴县| 尚志市| 高清| 东宁县| 老河口市| 宜兴市| 栾城县| 金门县| 太谷县| 普洱| 白银市|