Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 24
"is" checks the id of each list-object and not the elements. It behaves similar to print(id(nap_list) == id(lap_list))
18th Apr 2019, 10:20 AM
Thoq!
Thoq! - avatar
+ 13
lap_list is an empty list. nap_list is an empty list. They have the same value (lap_list == nap_list), but they are not the same list (nap_list is not lap_list).
18th Apr 2019, 9:31 AM
Anna
Anna - avatar
+ 11
"Is" function is use to compare the id of each object. The == operator compares the values of both the operands and checks for value equality. Whereas( is) operator checks whether both the operands refer to the same object or not. This. Code can be written as print(id(lap_list)==id(nap_list)) Thanks
18th Apr 2019, 5:19 PM
Prince PS[Not_Active]
Prince PS[Not_Active] - avatar
+ 7
Lito Delcid what if i want to compare the elements inside?? what should i use??
18th Apr 2019, 7:15 PM
Alhussein Gomma
Alhussein Gomma - avatar
+ 6
Use == operator to compares the two values.
19th Apr 2019, 6:51 AM
Joseph Machika
Joseph Machika - avatar
+ 6
The IDs of two lists are different. This would be True:👇 lap_list=[] nap_list=lap_list print(nap_list is lap_list)
19th Apr 2019, 11:08 AM
Amer
Amer - avatar
+ 5
Because in this both list has different id that why it is false
19th Apr 2019, 6:55 AM
Kamal Pal
Kamal Pal - avatar
+ 3
Moon and back to sleep now
18th Apr 2019, 6:50 PM
Hassan Zaniru
+ 3
to do it properly you could use == operator
19th Apr 2019, 11:18 AM
Arman A
Arman A - avatar
+ 2
because their memory space is different. U can check it with id(variable)
19th Apr 2019, 6:09 AM
Shuv
Shuv - avatar
+ 1
vitalii i think u should wrap list comprehension part inside [ ] edit : and u are raising error yourself in case of "pineapple"
19th Apr 2019, 12:23 PM
Shuv
Shuv - avatar
+ 1
As Tom Packard and Anna said, nap_list and lap_list have not the same id, so if you want to compare them, it will be false.!!!!!!!!
19th Apr 2019, 5:02 PM
sontu limbu
sontu limbu - avatar
+ 1
All is id
19th Apr 2019, 5:06 PM
Bhavesh Sen
Bhavesh Sen - avatar
0
Why is appearing a mistake in the next code? class Pizza: def __init__(self, toppings): self.toppings = toppings @staticmethod def validate_topping(topping): if topping == "pineapple": raise ValueError("No pineapples!") else: return True ingredients = ["cheese", "onions", "spam", "pineapple"] if all(Pizza.validate_topping(i) for i in ingredients): pizza = Pizza(ingredients) print (ingredients)
19th Apr 2019, 12:20 PM
vitalii
vitalii - avatar