Can someone explain this ! | Sololearn: Learn to code for FREE!
+ 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

11th Jan 2019, 8:11 AM
Omkar Tripathi
Omkar Tripathi - avatar
7 odpowiedzi
+ 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.
11th Jan 2019, 8:46 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
Kishalaya Saha i dont want extra brackets also, i just want add numbers generated into list, as numbers not strings
11th Jan 2019, 8:53 AM
Omkar Tripathi
Omkar Tripathi - avatar
+ 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.
11th Jan 2019, 8:54 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 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. 😅
11th Jan 2019, 9:03 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
Kishalaya Saha OMG...thank u so much
11th Jan 2019, 9:06 AM
Omkar Tripathi
Omkar Tripathi - avatar
+ 1
Kishalaya Saha oka, thanks, can u also explain why there is no error for that line and what that text message means
11th Jan 2019, 8:57 AM
Omkar Tripathi
Omkar Tripathi - avatar
+ 1
You're welcome, Omkar Tripathi Happy coding! ☺
11th Jan 2019, 9:09 AM
Kishalaya Saha
Kishalaya Saha - avatar