Q:

How to check multiple variables against a value in Python?

belongs to collection: Python basic programs

0

Given multiple variables and they are assigned some values, we have to test a value with these variables.

Let, there are three variables ab and c and we have to check whether one or more variables have the given value.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to test multiple variables against a value in Python

a = 10
b = 20
c = 30

# method 1
if a == 10 or b == 10 or c == 10:
  print("True")
else:
  print("False")  

# method 2
if 10 in (a, b, c):
  print("True")
else:
  print("False")  

# method 3
if 10 in {a, b, c}:
  print("True")
else:
  print("False")

Output

True
True
True

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python | Program to define an integer value and pr... >>
<< Python | Typecasting Input to Integer, Float...