+ 1
Can someone explain this !
I created some code in python but it doesn't show error neither it is working correctly https://code.sololearn.com/cLr72MItiJdo/?ref=app
7 ответов
+ 2
What do you want it to do? In lines 5 and 7, you are appending generator objects to your list. If you don't want a generator, use a list (line 6) or set (line 4) instead.
+ 2
Kishalaya Saha i dont want extra brackets also, i just want add numbers generated into list, as numbers not strings
+ 2
Oh, then you need to use
aryan.extend([i for i in range(12,15,1)])
list.append() adds one element. If you feed it another list, it would be just a nested list inside the original. But list.extend() adds all the elements from the argument to the original list.
+ 2
In each of the lines 4-7, you're adding one new object to the list. They are, respectively, a set, a generator, a list, and then another generator. When you print aryan, it just shows those 4 objects in addition to the original elements. You'll learn about sets and generators soon enough in the Python tutorial.
There is no error because everything is correct, just not what you expected it to be. 😅
+ 2
Kishalaya Saha OMG...thank u so much
+ 1
Kishalaya Saha oka, thanks, can u also explain why there is no error for that line and what that text message means
+ 1
You're welcome, Omkar Tripathi
Happy coding! ☺