Tuesday, May 2, 2023

#PYTHON(DAY6)List and list indexing in python

 

#PYTHON(DAY6)

List and list indexing in python

Lists

x = [1,2.2,3.3j,'four',print,str,True]
print(x,len(x),type(x))
print(x[0], x[-1], sep ='\n')

INDEX()

x = [1,2,3,4]
x.index(5)

INDEXING

Positive Indexing

INDEXING
thislist = ["apple", "banana", "cherry"]
print(thislist[1])

Negative Indexing

thislist = ["apple", "banana", "cherry"]
print(thislist[-1])

range

thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
print(thislist[2:5])
x = range(1,21,3)
y = range(20,0,-2)
#z = range(20.5,1.5,0.5) # can not access float numbers
print(x, id(x))
print(y, id(y))
x = list(x)
print(x, type(x))
print()

y = list(y)
print(y,type(y))
x = range(3, 20, 2)
for n in x:
print(n)

No comments:

Post a Comment

Building Static Website(part6) HTML Lists

  Building Static Website (part6) HTML Lists Today, let us add some lists to our detailed view section by using html lists. Lists: List is a...