In this video, You will learn Python Lists.
"""Python List"""
"""
1. Lists store multiple items in a single variable.
2. Lists can store different data types while Array can't store.
3. Lists are mutable i.e Lists can be changed.
4. Lists allow duplicate values.
5. Lists insertion order is maintained.
6. Lists are represented using square brackets [] and
values are separated using comma (,).
"""
""" Create a List"""
Mylist = [10, "India", -50, 30.22, True, 10, 10]
print(Mylist)
"# type() function"
print(type(Mylist))
"# List() constructor"
MyList = list((10, "India", -50, 30.22, True, 10, 10))
print(MyList)
"type() function"
print(type(MyList))
"# Access Items in List:"
"# Using Indexing starts from 0, 1, 2, ..."
Mylist = [10, "India", -50, 30.22, True, 10, 10]
print(Mylist[6])
"# Using Negative Indexing starts from -1, -2, ..."
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
print(Mylist[-5])
"# Slicing in Lists"
"# In Slicing, range of index is provided that is" \
"Start index and End index"
"# End index-1 "
"# Last index is not considered in output and " \
"it runs upto the second last end index"
"# Example 1"
"# Start index and End index"
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
print(Mylist[0:3])
"# Example 2"
"# Leave End Index"
"# It will run upto the end of the list"
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
print(Mylist[4:])
"# Example 3"
"# Leave Start Index"
"# It will assume 0 as start index"
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
print(Mylist[:6])
"# Example 4"
"# Leave Start Index and End Index"
"# It will print the complete list"
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
print(Mylist[:])
"# Example 5"
"# Slicing using Negative indexing "
"# Slicing runs from Left to Right Direction or " \
"from start to end "
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
print(Mylist[-3:-1])
"# Example 6"
"# Slicing using Negative indexing "
"# Leave Start index"
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
print(Mylist[:-3])
"# Example 7"
"# Slicing using Negative indexing "
"# Leave End index"
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
print(Mylist[-7:])
"# Change Items in List"
"# By using index"
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
Mylist[1] = "France"
Mylist[6] = "Paris"
Mylist[4] = False
print(Mylist)
"# Iteration in List:"
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
"# Using For loop"
for x in Mylist:
print(x)
"# Repetition in List:"
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
"# using multiplication (*) "
print(Mylist*2)
"# Membership in List:"
Mylist = [10, "India", -50, 30.22, True, 10, 'Delhi']
"# using If and in keyword "
if 10 in Mylist:
print("Yes")
else:
print("No")
"# Length of a List:"
Mylist = [10, "India", -50, 30.22, True, 10, 10, 10]
"# using len() function"
"# How many items are available in the list including" \
"duplicate items"
print(len(Mylist))
"# Add Items in the list:"
See the next video...
Auf dieser Seite können Sie das Online-Video Python Tutorial | Python List | Access Items in List | Change Items in List | Slicing mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer GSS 01 Januar 1970 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 41 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!