B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP Access List Items in Python | LiveCodeProgramming
Python Installation First Python Program Control Flow if...else nested if else match-case logical-operators for loops while loops break / continue Functions Defining Functions Function Arguments Function return value Lambda Function Recursion Exception Handling Exception Handling Try Except Else and Finally Raise Exception Custom Exceptions File Handling File in python Read File Write File Append File Delete File Exception Handling

Accessing List Items in Python

You can access items in a Python list using indexing, slicing, or loops. Below are various ways to do it:

Python list के items को access करने के लिए हम indexing, slicing या loop का उपयोग कर सकते हैं। नीचे इसके तरीके दिए गए हैं:

1. Access by Index
students = ["Raj", "Simran", "Aman"]
print(students[0])
Output:
Raj
2. Negative Index
students = ["Raj", "Simran", "Aman"]
print(students[-1])
Output:
Aman
3. Access a Range (Slicing)
students = ["Raj", "Simran", "Aman", "Pooja"]
print(students[1:3])
Output:
["Simran", "Aman"]
4. Access From Start
students = ["Raj", "Simran", "Aman"]
print(students[:2])
Output:
["Raj", "Simran"]
5. Access Till End
students = ["Raj", "Simran", "Aman"]
print(students[1:])
Output:
["Simran", "Aman"]
6. Loop Through List
students = ["Raj", "Simran", "Aman"]
for student in students:
    print(student)
Output:
Raj
Simran
Aman
7. Check Item Existence
students = ["Raj", "Simran", "Aman"]
if "Simran" in students:
    print("Yes, Simran is in the list")
Output:
Yes, Simran is in the list