GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python: Check whether multiple variables have the same value - w3resource

Python: Check whether multiple variables have the same value

Last update on May 17 2025 05:43:03 (UTC/GMT +8 hours)


Variable Equality Checker

Write a Python program to check whether multiple variables have the same value.

Pictorial Presentation:

Check whether multiple variables have the same value


Sample Solution-1:

Python Code:

# Assign the value 20 to the variable x.
x = 20

# Assign the value 20 to the variable y.
y = 20

# Assign the value 20 to the variable z.
z = 20

# Check if all variables have the value 20 using the equality (==) operator.
if x == y == z == 20:
    print("All variables have the same value!")
  

Sample Output:

All variables have same value! 

Sample Solution-2:

Python Code:

# Define a function that checks if all variables passed as arguments have the same value.
def multiple_variables_equality(*vars):
    # Iterate through the variables in the argument list.
    for x in vars:
        # Check if the current variable is not equal to the first variable.
        if x != vars[0]:
            return "All variables do not have the same value."
    return "All variables have the same value."

# Call the function with different sets of variables and print the result.
print(multiple_variables_equality(2, 3, 2, 2, 2, 2))
print(multiple_variables_equality(10, 10, 10, 10))
print(multiple_variables_equality(-3, -3, -3, -3))  
  

Sample Output:

All variables have not same value.
All variables have same value.
All variables have same value. 

Flowchart:

Flowchart: Check whether multiple variables have the same value.


For more Practice: Solve these Related Problems:

  • Write a Python program to check if three different variables reference the same memory location.
  • Write a Python function to check if multiple variables have different values.
  • Write a Python program that determines equality of variables when stored in different data structures.
  • Write a Python program to check if two different variables hold the same mutable object.

Go to:

  • Python Basic Exercises Home ↩
  • Python Exercises Home ↩

Previous: Write a Python program to determine the largest and smallest integers, longs, floats.
Next: Write a Python program to sum of all counts in a collections.

Python Code Editor:

 

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.