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

22nd Feb 2020, 4:59 AM
Jatin Kumar
Jatin Kumar - avatar
8 Answers
+ 6
Is name_list.append(arg) not name_list.append[arg]
22nd Feb 2020, 5:08 AM
Cmurio
Cmurio - avatar
+ 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. '''
22nd Feb 2020, 5:07 AM
Cmurio
Cmurio - avatar
+ 1
append(arg) You have to use round parentheses, this is a function call. Square brackets are for list slicing.
22nd Feb 2020, 5:07 AM
Tibor Santa
Tibor Santa - avatar
+ 1
It works for me...
22nd Feb 2020, 5:18 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Got it. Thank you :)
22nd Feb 2020, 5:25 AM
Jatin Kumar
Jatin Kumar - avatar
0
thanks guys but still I am not able to print the list with appended name.
22nd Feb 2020, 5:12 AM
Jatin Kumar
Jatin Kumar - avatar
0
How many names do u intend to append to the list?
23rd Feb 2020, 2:42 PM
Yusuf Shuaib Olalekan
Yusuf Shuaib Olalekan - avatar
0
24th Feb 2020, 4:01 AM
Jatin Kumar
Jatin Kumar - avatar