logo-MindMajix
PostPythonPython
s
sumana reddy

Posted on 18th July 2024|10 views

0
votes

Python Is Not Defined

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

1 answers
Answers
P
naseer mohammad

Posted on 18th July 2024| views

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
Name
Course *
Email *
Phone Number