0
I am stucked at this python program please help me [solved]
list=[5,5,8,2,9] jh=list.index(9) print(jh) list[4]=40000 print(list[4]) co=len(list) #this line is not working print("length of list is: "+co) list.append(299999) print(list[5])
4 Respuestas
+ 4
#Try this one
list=[5,5,8,2,9]
jh=list.index(9)
print(jh)
list[4]=40000
print(list[4])
co=len(list)
print("length of list is: ",co)
list.append(299999)
print(list[5])
+ 4
Anjali kaur
len function returns int so co will be a type of int
But "length of list is:" is a string so you can't directly concat int with string
For this you need to cast co with str function
print ("length of the list is: " + str(co))
#this will now work
+ 3
♨️A.S. Raghuvanshi♨️ thanks it worked
+ 2
Anjali,
From this moment on, try not to use Python built-in class/function names as variable's name.
Here you define a `list` object named <list>. But `list` itself is a class name, so please choose a different name for the variable. Use of `list` as variable name shadows the original one, rendering it unusable.
list = [ 5, 5, 8, 2, 9 ]
another_list = list( range( 11 ) )
# use built-in function list()
# to create a `list` object
# error: <list> had been redefined
# it no longer is a callable