Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Python use subscript to get a single value of a list

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains how Python uses subscript to get a single value of the list. Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how Python uses subscript to get a single value of a list.

Subscript description

1. The subscript used exceeds the number of values in the list, and Python will give the IndexError error message.

2. The subscript can only be an integer, not a floating point value.

3. The list can also contain other list values.

Example

List1 = [1JI 2JI 43] print (list1) print (list1 [0]) 1. If the subscript used exceeds the number of values in the list, Python will give the IndexError error message. Print (list1 [5]) IndexError: list index out of range 2. The subscript can only be an integer, not a floating point value. The following example will cause a TypeError error: print (list1 [5. 0]) TypeError: list indices must be integers or slices, not float 3. The list can also contain other list values. The values in the list of these lists can be accessed through multiple subscripts, like this: list = [[1, 2, 3], [4, 5, 6]] print (list [0] [1]) print results: 2 so far, I believe you have a deeper understanding of "Python how to use subscript to get a single value of the list". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report