Last answered:

04 Oct 2022

Posted on:

29 Nov 2021

0

What's the difference between "and" and "&" in Python?

I looked this up on the internet and it says " & acts on various bits and performs operations bit by bit."
I am not sure what this means. Would anyone be able to tell me in what situations I should use 'and' and when I should use '&' instead?

1 answers ( 0 marked as helpful)
Posted on:

04 Oct 2022

0

Well, my answer will be only focused on the scope of this course

1- If the conditions are meant to return a single Boolean expression [True/False] or one of them will give a single value >> Use 'and'
for example,

#Here we use and as if we executed one of the conditions, it would return 'TRUE/FALS'
5==5 and 8>5
True

1- If the conditions are meant to return an array or a list >> Use '&'
This is the same example mentioned in the video

Submit an answer