Diffrence between two

46 views
Skip to first unread message

Ashutosh Mishra

unread,
Oct 28, 2020, 7:29:15 AM10/28/20
to Django users
for i in grocery:
if i.store_type=="Alcohol" or "Both":(1)
if i.store_type=="Alcohol" or i.store_type=="Both":(2)

can anyone tell me the diffrence between two statements,I am getting two diffrent results

Andréas Kühne

unread,
Oct 28, 2020, 7:37:13 AM10/28/20
to django...@googlegroups.com
for i in grocery:
if i.store_type=="Alcohol" or "Both":(1)
This line checks if  i.store_type is "Alcohol" or if the string "Both" is Truthy - which it is because it is not '' or None - this if statement will always be True.

if i.store_type=="Alcohol" or i.store_type=="Both":(2)
This line checks if the i.store_type is 'Alcohol' or if the i.store_type is 'Both'. This if statement will only be true if the store_type is 'Alcohol' or 'Both'.

Regards,

Andréas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3d26d63e-e725-4074-bbd1-db05e87e402an%40googlegroups.com.

Ashutosh Mishra

unread,
Oct 28, 2020, 7:44:25 AM10/28/20
to Django users
thanks
Reply all
Reply to author
Forward
0 new messages