Feedback
Got a suggestion for improvement? Anything goes.
Found a bug? Let us know. For other inquries feel free to contact us about anything at all.
Depvana •
about •
legal •
contact •
contribute •
Depvana is independent. Help keep it that way.
© 2024 Depvana aps.
Login to add a hashtag.
Hashtags
Tags
Bookmark Mark
Topic python essentials
Public room public room
Moderators •   sys
Depth •  Tech > programming > python essentials
Purpose • 
Essential python knowledge sharing.
59
1
0
More
Copy link
Report
Visible to the public Public post
Attachments • images • video webm/mp4 • max size 4096KiB.
Attachments • images • video webm/mp4 • max 4MB.
Filter by  •  Newest
Newest
Sort posts in decending order by date
Oldest
Sort posts in ascending order by date
sys@335 
More
Copy link
Report
Existence of variables!

To check the existence of a local variable:

if 'myVar' in locals():
  # myVar exists.

To check the existence of a global variable:

if 'myVar' in globals():
  # myVar exists.

To check if an object has an attribute:

if hasattr(obj, 'attr_name'):
  # obj.attr_name exists.