A list in Python is a collection of items that are ordered, changeable (mutable), and allow duplicate values. Lists are written with square brackets []
.
Python में list एक ऐसा collection है जिसमें items ordered होते हैं, उन्हें बदला जा सकता है (mutable होते हैं), और duplicate values भी हो सकती हैं। इसे []
में लिखा जाता है।
fruits = ["apple", "banana", "cherry"]
print(fruits)
Output:
["apple", "banana", "cherry"]
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
print(fruits)
Output:
["apple", "banana", "cherry", "orange"]
fruits = ["apple", "banana", "cherry"]
fruits.insert(1, "grape")
print(fruits)
Output:
["apple", "grape", "banana", "cherry"]
fruits = ["apple", "banana", "cherry"]
fruits.remove("banana")
print(fruits)
Output:
["apple", "cherry"]
fruits = ["apple", "banana", "cherry"]
fruits.pop()
print(fruits)
Output:
["apple", "banana"]
fruits = ["banana", "apple", "cherry"]
fruits.sort()
print(fruits)
Output:
["apple", "banana", "cherry"]
fruits = ["apple", "banana", "cherry"]
fruits.reverse()
print(fruits)
Output:
["cherry", "banana", "apple"]
fruits = ["apple", "banana", "cherry"]
print(len(fruits))
Output:
3