Unit: Unit 7: Introduction to Classes • Interactive Practice
Interactive Python programming tutorial and practice in your browser.
# Inspecting objects and verifying Python's 'Everything is an Object' architecture
number = 42
text = "Hello"
def greet():
return "Hi!"
# 1. Everything is an object with a type and id
print("Integer is object of type:", type(number))
print("String is object of type:", type(text))
print("Function is object of type:", type(greet))
# 2. Introspection tools: hasattr and getattr
class Config:
def __init__(self):
self.env = "production"
self.port = 8080
cfg = Config()
print("Has 'port' attribute?", hasattr(cfg, "port"))
print("Dynamic lookup of 'env':", getattr(cfg, "env"))