0
What is wrong with my code ?
In the code I wish to append the list with the input obtained from the name. but it shows ""TypeError: 'function' object is not subscriptable. What is wrong with this code and how can I get this task done. https://code.sololearn.com/cQlRZcBtJn10/?ref=app
8 Answers
+ 6
Is
name_list.append(arg)
not name_list.append[arg]
+ 4
name_list=[]
def names(arg):
name_list.append(arg)
name=input("Enter your name: ")
names(name)
print(name_list)
'''
In this code I want to store the names added as input in the name_list.
'''
+ 1
append(arg)
You have to use round parentheses, this is a function call.
Square brackets are for list slicing.
+ 1
It works for me...
+ 1
Got it. Thank you :)
0
thanks guys but still I am not able to print the list with appended name.
0
How many names do u intend to append to the list?
0
Yusuf Shuaib Olalekan more than 2.