+ 1
Please Explain why a is not equal to b
8 Réponses
+ 5
Because l.sort() function does not return any value, instead it just sort the list "l" . And comparing "none" with a sorted list "b" will return false.
Here👇 see this code for better understanding
https://code.sololearn.com/cbaHIljTN34K/?ref=app
+ 5
Because as Arsenic said, .sort() does not return any value. It just sorts the list. sorted on the other hand, returns a new list
+ 4
sorted returns a new list
sort modifies the list you are sorting
Throw some print statements in there and you'll see they are not equal
+ 4
This is because l.sort() did not return any value thus, "a" is uninitialised.
+ 4
Run this:
l= [ 1,9,65,88,40 ]
a = l.sort ()
b= sorted (l)
print('a =',a)
print('b =',b)
if a==b:
print (1+1)
else:
print (0)
+ 4
Arsenic
My internet is a bit slow, like me.
By the time I posted, you gurus had already supplied the perfect answers
+ 3
Rik Wittkopp this is what my code is doing.
+ 2
Why it is showing NONE for print(a)