11 ответов
+ 13
Madhav Panicker i think you are looking for some think called as '.append()' method of list,
Here i have made a code to understand the difference between them..
Hope that helped 😄
Edit: anything you would like to add HonFu?
https://code.sololearn.com/cYmDd0KiwhsI/?ref=app
+ 11
Try printing it and see why :)
a = ['p', 'y', 't', 'h', 'o', 'n']
b = ['python']
of course they are not equal! ;)
+ 6
But also so convenient!
Basically Python does for you what you would otherwise do anyway, like comparing each item.
You can also bool a container just by naming the container itself, not its length.
apples = []
if not apples:
postpone_cake_baking()
+ 5
A string is actually an array of characters. When using "+=" to add two arrays, you add the entries of the array to the end of the first one.
In this case, the individual characters in the string are "unpacked" into the empty list.
The .append() method takes an ENTIRE variable and adds it to a list. In this case, using the append() instead of += would have resulted in True
For example:
ls = []
ls += [1, 2, 3]
ls.append([1,2,3])
print(ls)
>>> [1, 2, 3, [1, 2, 3]]
+ 3
The problem is that you cant just compare arrays.
You have to compare each element on your own.
Edit:
Looks like i was wrong and you can compare arrays in python.
look at Kuba Siekierzyński answer.
+ 3
About that i am aware. It was just that i had arrays memorized as no language can do it properly and i always do it myself. :D
+ 3
Sebriel But a==c is True :)
0
Here I leave a code that shows Kuba Siekierznski's explanation:
https://code.sololearn.com/cEF4eOGcp1sc/?ref=app
0
Oh Yes! Should I add it to the example?