object introspection

# object introspection: it is an ability to determine the type of an object at runtime
# python provides some built-in functions that are used for object introspection. They are
# 1. type(): this function returns the type of an object.
# 2. dir(): this function return list of methods and attributes associated with that object.
# 3. str(): this function converts everything into a string.
# 4. id(): this function returns a special id of an object.
# there are many are there

# type()
import random
print(type(random))
print(type([1,2,3]))
#-------------------------------

# dir()
a=[1,2,3]
print(dir(a))
#-------------------------------

# str()
a=1
print(type(a))
print(type(str(a)))
#------------------------------

# id()
b=1
print("id:",id(b))

Comments

Popular posts from this blog

Tokens in C

Steps taken by a compiler to execute a C program

Variables and Data Types in C