A class defines a collection of instance variables and methods to specify an object type. A class can be used to make as many object instances of the type of object as needed. An object is an identified entity with certain attributes (data members) and behaviours (member functions). Group of objects having similar characteristics and behaviour are the instance of the same class.
Python is a dynamic programming language and due to its flexibility Python has a significant advantage over statically typed languages. Python Code can be dynamically imported and classes can be dynamically created at run-time.
Classes can be dynamically created using the
type() function in Python. The
type() function is used to return the type of the object.
The above syntax returns the type of object.
class 'str' class 'int'
Creating Dynamic Classes in Python
Classes can be created dynamically using the below syntax:
type(name, bases, attributes) Parameters: name: The user defined name of the class bases: A list of base classes, and its type is tuple attributes: the data members and methods contained in the class
The above Syntax returns a new type of object.
constructor argument Geeks 4 geeks! 1706256 Geeks for GeeksClass Dynamically Created!
In the above program, class
Geeks is dynamically created which has a constructor. The data members of
int_attribute and member functions of
classMethod(). An object
obj of class
Geeks is created and all the data members are assigned and displayed, all the member functions of
Geeks are also called.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- How to Dynamically Load Modules or Classes in Python
- Why Python is called Dynamically Typed?
- Python | How to dynamically change text of Checkbutton
- wxPython - Dynamically enable and disable tools in toolbar using button
- Abstract Classes in Python
- Data Classes in Python | An Introduction
- Data Classes in Python | Set 2 (Decorator Parameters)
- Data Classes in Python | Set 3 (dataclass fields)
- Data Classes in Python | Set 4 (Inheritance)
- Data Classes in Python | Set 5 (post-init)
- Data Classes in Python | Set 6 (interconversion to and from other datatypes)
- Python Classes and Objects
- The Ultimate Guide to Data Classes in Python 3.7
- wxPython - Create Radio Button using Create() function
- wxPython - Create Static Box using Create() method
- Create a Website Alarm Using Python
- Create simple Blockchain using Python
- Create and Access a Python Package
- Create a stopwatch using python
- Python | Create and write on excel file using xlsxwriter module
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.