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

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]
主站蜘蛛池模板: 老河口市| 绍兴县| 葵青区| 安平县| 灵山县| 平阳县| 阿鲁科尔沁旗| 武城县| 新余市| 丰宁| 乌恰县| 宜兴市| 汝城县| 浙江省| 沧州市| 慈利县| 鄂托克前旗| 巴里| 贺兰县| 连城县| 泌阳县| 珠海市| 庆城县| 虎林市| 岳西县| 汉阴县| 庆安县| 清新县| 瑞丽市| 新丰县| 仁寿县| 石城县| 达州市| 皋兰县| 罗山县| 合水县| 体育| 乌审旗| 海丰县| 赣州市| 宣城市|