Post

PythonPython

s
sumana reddy

Posted on 23rd April 2024|10 views

0
votes

Python Is Not Defined

How do you check if a variable is not defined in Python?

Answers
P
naseer mohammad

Posted on 23rd April 2024

You can check the variable is defined or not by using the below code

try:

  a = 1

except NameError:

  print("Variable isn’t defined")

else:

  print("Variable is defined")

try:

  b

except NameError:

  print("Variable isn’t defined")

else:

  print("Variable is defined")

 

Improve your knowledge in Python from scratch using Python Online Course.

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos