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

Accessing values in lists

We can access the values from a list by using index values. We will specify the index number in [ and ]. Index starts from 0. Refer to the given example:

#!/usr/bin/python3
cities = ['Mumbai', 'Bangalore', 'Chennai', 'Pune']
numbers = [1, 2, 3, 4, 5, 6, 7 ]
print (cities[0])
print (numbers[1:5])


Output:
Mumbai
[2, 3, 4, 5]
主站蜘蛛池模板: 仁布县| 邵武市| 钟祥市| 隆回县| 虞城县| 刚察县| 余庆县| 凤山市| 陆良县| 锦州市| 临颍县| 江孜县| 石河子市| 尉氏县| 丹凤县| 涿州市| 天峨县| 庆阳市| 黑龙江省| 莆田市| 资源县| 新营市| 寿阳县| 洪雅县| 沅陵县| 卫辉市| 华坪县| 临桂县| 张掖市| 保山市| 平和县| 佳木斯市| 新密市| 济宁市| 水城县| 库车县| 达孜县| 鄂托克旗| 合阳县| 新乡县| 托克逊县|