Python logical operator 'and'

0 votes

Please help understand the working of and

a=10 
b=50 
print(a and b) # 50
print(b and a) # 10

Why different results?

Jan 28 in Python by Lakheer
39 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

If you use and on two or more non-zero numbers then the last number would be printed as output. If one of those numbers is 0 then 0 will be the output.

print (a and b)

Here is the last number and because a is not zero, b is printed.

print (b and a)

And in this case, is the last number and because b is not zero, a is printed.

answered Jan 28 by Omkar
• 65,820 points

Related Questions In Python

+4 votes
6 answers

Does Python have a ternary conditional operator like C does?

Yes, the syntax is: a if condition else ...READ MORE

answered Apr 13, 2018 in Python by Nietzsche's daemon
• 4,260 points
67 views
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,710 points
36 views
0 votes
1 answer

what are "and" and "or" operators in Python?

AND - True if both the operands ...READ MORE

answered Apr 17, 2018 in Python by Johnathon
• 9,030 points
17 views
0 votes
2 answers

What do you mean by python scripting? What is a script and a module in python?

A scripting language is a programming language ...READ MORE

answered Mar 14 in Python by rajesh kumar
1,521 views
0 votes
0 answers

what is a bitwise operator in python?

can you show some operations using bitwise ...READ MORE

Apr 8 in Python by Waseem
• 1,910 points
9 views
0 votes
0 answers

what is the logical AND operator in python?

how do i use it in a ...READ MORE

Apr 12 in Python by Waseem
• 1,910 points
17 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
19 views
+6 votes
4 answers

Python and Pygame: Difference

Python is a programming language. PyGame is a ...READ MORE

answered Oct 24, 2018 in Python by Priyaj
• 56,100 points
54 views
+3 votes
2 answers

What does Python _init_ and self do?

Hey @Anirudh!  Self The self keyword is used to access ...READ MORE

answered Oct 31, 2018 in Python by Omkar
• 65,820 points
41 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.