🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 151 (from laksa021)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
✅
CRAWLED
2 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.edureka.co/blog/python-metaclasses/
Last Crawled2026-04-14 06:16:06 (2 days ago)
First Indexed2020-07-17 19:56:49 (5 years ago)
HTTP Status Code200
Meta TitleIntroduction to Python Metaclass | Python Programming Tutorial | Edureka
Meta DescriptionThis Python metaclass article will help you understand where and how to implement them with examples implementing custom Metaclass in Python.
Meta Canonicalnull
Boilerpipe Text
A Python Metaclass sets the behavior and rules of a class. Metaclass helps in modifying the instantiation of a class and is fairly complex and one of the advanced features of Python programming. Through this article, I will be discussing in-depth concepts of Python Metaclass, its properties, how and when to use a Metaclass in Python. This article covers the following concepts:  What is Python Metaclass? Classes and Objects in Python How Does Python Metaclass Work? Python Metaclass is one of the advanced features associated with Object-Oriented Programming concepts of Python. It determines the behavior of a class and further helps in its modification. Every class created in Python has an underlying Metaclass. So when you’re creating a class, you are indirectly using the Metaclass. It happens implicitly, you don’t need to specify anything. Metaclass when associated with metaprogramming determines the ability of a program to manipulate itself. Learning Metaclass might seem complex but let’s get a few concepts of classes and objects out of the way first, so that it’s simple to understand.   Classes and Objects in Python A class is a blueprint, a logical entity having objects.  A simple class when declared does not have any memory allocated, it happens when an instance of a class is created. Through the objects created, one can access the class. The class simply works as a template. The property of an object essentially means that we can interact with it at runtime, pass parameters like variables, store, modify, and can also interact with it. The class of an object can be checked by using the __class__ attribute. Let’s see  this simple example:  class Demo: pass #This is a class named demo test=Demo() print(test.__class__) #shows class of obj print(type(test)) #alternate method Output: <class '__main__.Demo'> Python heavily deals with the concept of classes and objects and allows easy and smooth application development. But what makes Python different from languages like Java and C ? Everything in Python can be defined as an object having attributes and methods. Keynote is that classes in Python are nothing but another object of a bigger class. A class defines rules for an object. Similarly, a Metaclass is responsible for assigning behaviors for the classes. We have learned that Class is an object, and like every object has an instance, a class is an instance of a Metaclass.   But there are languages like Ruby and Objective-C which support Metaclasses as well. So, what makes Python Metaclass better and why should you learn it?  The answer is the dynamic class in Python. Let’s take a closer look at it.   Dynamic Class in Python Python is a dynamic programming language and allows the creation of a class at runtime. Unlike other languages like  C++, which only allows the class creation at compile time. In terms of flexibility, Python has an advantage over other languages that are statically typed. The difference between dynamic and statically typed language isn’t much, but in Python, it becomes more useful because it provides metaprogramming.  But what if I tell you that there’s another key feature that distinguishes Python from other programming languages? Languages like Java or C++ have data types like float, char, int, etc. whereas Python treats each variable as an object. And each object belongs to a class like an int class or str class. You can simply check the class of any variable using a built-in function called type(). number = 10993 print("Type associated is:", type(number)) name = "Aishwarya" print("Type associated is:", type(name)) Output:  Type associated is:  <class 'int'> Type associated is: <class 'str'> Now that you understand everything in Python has a type associated with it. In the next topic, we will try to understand how Metaclass actually works. Whenever a class is created the default Metaclass which is type class gets called instead.  Metaclass carries information like name, set of a base class, and attributes associated with the class. Hence, when a class is instantiated type class is called carrying these arguments. Metaclass can be created via two methods: Type class Custom Metaclass Let’s move on to type class and how you can create one. Type Class Python has a built-in Metaclass called type . Unlike Java or C, where there are primary data types. Every variable or object in Python has a class associated with it. Python use Type class behind-the-scenes to create all the classes. In the previous topic, we saw how we can check the class of an object by using type(). Let’s take an example of how we can define a new type, by creating a simple class. class Edureka(): obj = Edureka() print(type(obj)) Output: <class '__main__.Edureka'> print(type(Edureka)) Output: <class 'type'> In the above code, we have a class called Edureka, and an object associated. We created a new type called Edureka by simply creating a class named itself after the type. In the second code, when we check the type of Edureka class, it results as ‘type’. So, unless defined otherwise, Metaclasses use type class to create all the other classes. We can access Type class via two methods: When we pass parameters through type class, it uses the following syntax. type(__name__, __base__, attributes) where, the name is a string and carries the class name the base is a tuple and helps create subclasses an attribute is a dictionary and assigns key-value pairs Since classes in Python behave similar to the objects, their behavior could be altered in the same way. We can add or remove methods within a class similar to how we do with objects.     Now that you know Metaclass creates all the other classes in Python and defines their behavior using type class. But then you must be wondering, is there any other way we can create Metaclass? So, let’s see how to create a custom Metaclass that.  Ready to unlock the power of data? Dive into Python for Data Science today! Whether you’re analyzing trends, building predictive models, or extracting valuable insights, Python’s versatile libraries like NumPy, pandas, and scikit-learn empower you to conquer any data challenge Custom Metaclass in Python Now that we know and understand how the type class works. It’s time to learn how we can create our custom Metaclass. We can modify the working of classes by carrying actions or code injection. To achieve this, we can pass Metaclass as a keyword while creating a class definition. Alternatively, we can achieve this by simply inheriting a class that has been instantiated through this Metaclass keyword.   At the time of creating a new class, Python looks for the __metaclass__   keyword. In case, if it isn’t present. It follows the type class hierarchy. After Python executes all the dictionary in a namespace, it invokes type object which creates objects of a class. There are two methods that we can use to create custom Metaclass. class EduFirst(type): def __new__(cls, name, base_cls, dict): pass class EduSecond(type): def __init__(self, name, base_cls, dict): pass Let me explain these two methods in detail: __new__():   is used when a user wants to define a dictionary of tuples before the class creation. It returns an instance of a class and is easy to override/manage the flow of objects. __init__() : It’s called after the object has already been created and simply initializes it.  What is __call__ in Python? In the official Python documents , the __call__ method can be used to define a custom Metaclass. Also, we can override other methods like __prepare__ when calling a class to define custom behavior.  Much like how a class behaves like a template to create objects, in the same way, Metaclass acts like a template for the class creation. Therefore, a Metaclass is also known as a class factory.  See the next example:  class Meta(type): def __init__(cls, name, base, dct): cls.attribute = 200 class Test(metaclass = Meta): pass Test.attribute Output: 200 Metaclass allows class customization. There are various other effective and much simpler ways through which the same output can be achieved. One such example is using Decorators.  Decorator is a popular feature of Python which allows you to add more functionality to the code. A decorator is a callable object which helps modify the existing class or even a function. During compilation, part of code calls and modifies another part. This process is also known as metaprogramming. Decorator Metaclass Returns the same class after making changes (e.g.: monkey-patching) We use Metaclass whenever a new class is created Lacks flexibility Provides flexibility and customization of classes Isn’t compatible to perform subclassing Provides subclassing by using inheritance and converting object methods to static methods for better optimization def decorator(cls): class NewClass(cls): attribute = 200 return NewClass @decorator Class Test1: pass @decorator Class Test2: pass Test1.attribute Test2.attribute Output: 200 Decorator in Python is a very useful and powerful tool that helps change the behavior of a function without actually changing any of the code. This comes handy when you want to modify a part of the program while debugging, instead of rewriting the function or changing the entire program. Instead,  you can simply write a single line decorator and it will take care of the rest.  This brings us to the end of the session. Hopefully, this article helped you understand what is Metaclass and how and when to use it.  If you found this article on “Python Metaclass” relevant, check out   Edureka’s Python Programming Certification Course   a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe. We are here to help you with every step on your journey and come up with a curriculum that is designed for students and professionals who want to be a   Python developer . The course is designed to give you a head start into Python programming and train you for both core and advanced Python concepts along with various   Python frameworks   like   Django. If you come across any questions, feel free to ask all your questions in the comments section of “Python Metaclass”. Our team will be glad to answer.
Markdown
![](https://googleads.g.doubleclick.net/pagead/viewthroughconversion/977137586/?value=0&guid=ON&script=0) Subscribe [![edureka logo](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20150%2043'%3E%3C/svg%3E)![edureka logo](https://d1jnx9ba8s6j9r.cloudfront.net/img/Edureka_SNVA_New1_Ver_Enter_Logo.webp)](https://www.edureka.co/) - Training in Top Technologies [DevOps Certification Training](https://www.edureka.co/devops-certification-training) [AWS Architect Certification Training](https://www.edureka.co/aws-certification-training) [Big Data Hadoop Certification Training](https://www.edureka.co/big-data-hadoop-training-certification) [Tableau Training & Certification](https://www.edureka.co/tableau-certification-training) [Python Certification Training for Data Science](https://www.edureka.co/data-science-python-certification-course) [Selenium Certification Training](https://www.edureka.co/selenium-certification-training) [PMP® Certification Exam Training](https://www.edureka.co/pmp-certification-exam-training) [Robotic Process Automation Training using UiPath](https://www.edureka.co/robotic-process-automation-training) [Apache Spark and Scala Certification Training](https://www.edureka.co/apache-spark-scala-certification-training) [All Courses](https://www.edureka.co/all-courses) - Career Related Programs [Data Scienctist Masters Program](https://www.edureka.co/masters-program/data-scientist-certification) [Devops Engineer Masters Program](https://www.edureka.co/masters-program/devops-engineer-training) [Cloud Architect Masters Program](https://www.edureka.co/masters-program/cloud-architect-training) [BIg Data Architect Masters Program](https://www.edureka.co/masters-program/big-data-architect-training) [Machine Learning Engineer Masters Program](https://www.edureka.co/masters-program/machine-learning-engineer-training) [Full Stack Web Developer Masters Program](https://www.edureka.co/masters-program/full-stack-developer-training) [Business Intelligence Masters Program](https://www.edureka.co/masters-program/business-intelligence-certification) [Data Analyst Masters Program](https://www.edureka.co/masters-program/data-analyst-certification) [Test Automation Engineer Masters Program](https://www.edureka.co/masters-program/automation-testing-engineer-training) [All Programs](https://www.edureka.co/search?cl[]=584&cl[]=520&cl[]=585&cl[]=781&cl[]=457&cl[]=468&cl[]=479&cl[]=482) - [Webinars](https://www.edureka.co/webinars) - [Ebook NEW](https://www.edureka.co/blog/ebook/) - [Explore Online Courses](https://www.edureka.co/all-courses) - Subscribe - [Become a Certified Professional](https://www.edureka.co/blog/python-metaclasses/) - Back - [Home](https://www.edureka.co/blog/) - Categories - [Online Courses](https://www.edureka.co/all-courses) - [Webinars](https://www.edureka.co/webinars) - [Ebook NEW](https://www.edureka.co/blog/ebook/) - [Community](https://www.edureka.co/community) - Categories - [Artificial Intelligence](https://www.edureka.co/blog/python-metaclasses/#show_category_400) [AI vs Machine Learning vs Deep Learning](https://www.edureka.co/blog/ai-vs-machine-learning-vs-deep-learning/)[Machine Learning Algorithms](https://www.edureka.co/blog/machine-learning-algorithms/)[Artificial Intelligence Tutorial](https://www.edureka.co/blog/artificial-intelligence-tutorial/)[What is Deep Learning](https://www.edureka.co/blog/what-is-deep-learning)[Deep Learning Tutorial](https://www.edureka.co/blog/deep-learning-tutorial)[Install TensorFlow](https://www.edureka.co/blog/install-tensorflow)[Deep Learning with Python](https://www.edureka.co/blog/deep-learning-with-python/)[Backpropagation](https://www.edureka.co/blog/backpropagation/)[TensorFlow Tutorial](https://www.edureka.co/blog/tensorflow-tutorial/)[Convolutional Neural Network Tutorial](https://www.edureka.co/blog/convolutional-neural-network/)[VIEW ALL](https://www.edureka.co/blog/category/artificial-intelligence/) - [BI and Visualization](https://www.edureka.co/blog/python-metaclasses/#show_category_149) [What is Tableau](https://www.edureka.co/blog/what-is-tableau/)[Tableau Tutorial](https://www.edureka.co/blog/tableau-tutorial/)[Tableau Interview Questions](https://www.edureka.co/blog/interview-questions/top-tableau-interview-questions-and-answers/)[What is Informatica](https://www.edureka.co/blog/what-is-informatica/)[Informatica Interview Questions](https://www.edureka.co/blog/interview-questions/top-informatica-interview-questions-2016/)[Power BI Tutorial](https://www.edureka.co/blog/power-bi-tutorial/)[Power BI Interview Questions](https://www.edureka.co/blog/interview-questions/power-bi-interview-questions/)[OLTP vs OLAP](https://www.edureka.co/blog/oltp-vs-olap/)[QlikView Tutorial](https://www.edureka.co/blog/qlikview-tutorial/)[Advanced Excel Formulas Tutorial](https://www.edureka.co/blog/tutorial-on-advanced-excel-formulas/)[VIEW ALL](https://www.edureka.co/blog/category/business-intelligence/) - [Big Data](https://www.edureka.co/blog/python-metaclasses/#show_category_142) [What is Hadoop](https://www.edureka.co/blog/what-is-hadoop/)[Hadoop Architecture](https://www.edureka.co/blog/introduction-of-hadoop-architecture/)[Hadoop Tutorial](https://www.edureka.co/blog/hadoop-tutorial/)[Hadoop Interview Questions](https://www.edureka.co/blog/interview-questions/top-hadoop-interview-questions)[Hadoop Ecosystem](https://www.edureka.co/blog/hadoop-ecosystem)[Data Science vs Big Data vs Data Analytics](https://www.edureka.co/blog/data-science-vs-big-data-vs-data-analytics/)[What is Big Data](https://www.edureka.co/blog/what-is-big-data/)[MapReduce Tutorial](https://www.edureka.co/blog/mapreduce-tutorial/)[Pig Tutorial](https://www.edureka.co/blog/pig-tutorial/)[Spark Tutorial](https://www.edureka.co/blog/spark-tutorial/)[Spark Interview Questions](https://www.edureka.co/blog/interview-questions/top-apache-spark-interview-questions-2016/)[Big Data Tutorial](https://www.edureka.co/blog/big-data-tutorial)[Hive Tutorial](https://www.edureka.co/blog/hive-tutorial/)[VIEW ALL](https://www.edureka.co/blog/category/big-data-analytics/) - [Blockchain](https://www.edureka.co/blog/python-metaclasses/#show_category_398) [Blockchain Tutorial](https://www.edureka.co/blog/blockchain-tutorial/)[What is Blockchain](https://www.edureka.co/blog/what-is-blockchain/)[Hyperledger Fabric](https://www.edureka.co/blog/hyperledger-fabric/)[What Is Ethereum](https://www.edureka.co/blog/what-is-ethereum/)[Ethereum Tutorial](https://www.edureka.co/blog/ethereum-tutorial-with-smart-contracts/)[Blockchain Applications](https://www.edureka.co/blog/blockchain-applications/)[Solidity Tutorial](https://www.edureka.co/blog/solidity-tutorial/)[Blockchain Programming](https://www.edureka.co/blog/blockchain-programming)[How Blockchain Works](https://www.edureka.co/blog/how-blockchain-works/)[VIEW ALL](https://www.edureka.co/blog/category/blockchain/) - [Cloud Computing](https://www.edureka.co/blog/python-metaclasses/#show_category_41) [What is AWS](https://www.edureka.co/blog/what-is-aws/)[AWS Tutorial](https://www.edureka.co/blog/amazon-aws-tutorial/)[AWS Certification](https://www.edureka.co/blog/aws-certification-careers/)[Azure Interview Questions](https://www.edureka.co/blog/interview-questions/azure-interview-questions/)[Azure Tutorial](https://www.edureka.co/blog/microsoft-azure-tutorial)[What Is Cloud Computing](https://www.edureka.co/blog/what-is-cloud-computing/)[What Is Salesforce](https://www.edureka.co/blog/what-is-salesforce/)[IoT Tutorial](https://www.edureka.co/blog/iot-tutorial/)[Salesforce Tutorial](https://www.edureka.co/blog/salesforce-tutorial)[Salesforce Interview Questions](https://www.edureka.co/blog/interview-questions/salesforce-interview-questions/)[VIEW ALL](https://www.edureka.co/blog/category/cloud-computing/) - [Cyber Security](https://www.edureka.co/blog/python-metaclasses/#show_category_714) [Cloud Security](https://www.edureka.co/blog/cloud-security/)[What is Cryptography](https://www.edureka.co/blog/what-is-cryptography/)[Nmap Tutorial](https://www.edureka.co/blog/nmap-tutorial/)[SQL Injection Attacks](https://www.edureka.co/blog/sql-injection-attack)[How To Install Kali Linux](https://www.edureka.co/blog/how-to-install-kali-linux/)[How to become an Ethical Hacker?](https://www.edureka.co/blog/how-to-become-an-ethical-hacker/)[Footprinting in Ethical Hacking](https://www.edureka.co/blog/footprinting-ethical-hacking-kali-linux/)[Network Scanning for Ethical Hacking](https://www.edureka.co/blog/network-scanning-kali-ethical-hacking/)[ARP Spoofing](https://www.edureka.co/blog/python-arp-spoofer-for-ethical-hacking)[Application Security](https://www.edureka.co/blog/application-security-tutorial/)[VIEW ALL](https://www.edureka.co/blog/category/cyber-security/) - [Data Science](https://www.edureka.co/blog/python-metaclasses/#show_category_48) [Python Pandas Tutorial](https://www.edureka.co/blog/python-pandas-tutorial/)[What is Machine Learning](https://www.edureka.co/blog/what-is-machine-learning/)[Machine Learning Tutorial](https://www.edureka.co/blog/machine-learning-tutorial/)[Machine Learning Projects](https://www.edureka.co/blog/machine-learning-projects/)[Machine Learning Interview Questions](https://www.edureka.co/blog/interview-questions/machine-learning-interview-questions/)[What Is Data Science](https://www.edureka.co/blog/what-is-data-science/)[SAS Tutorial](https://www.edureka.co/blog/sas-tutorial/)[R Tutorial](https://www.edureka.co/blog/r-tutorial/)[Data Science Projects](https://www.edureka.co/blog/data-science-projects/)[How to become a data scientist](https://www.edureka.co/blog/data-scientist-skills/)[Data Science Interview Questions](https://www.edureka.co/blog/interview-questions/data-science-interview-questions/)[Data Scientist Salary](https://www.edureka.co/blog/data-scientist-salary/)[VIEW ALL](https://www.edureka.co/blog/category/data-science/) - [Data Warehousing and ETL](https://www.edureka.co/blog/python-metaclasses/#show_category_96) [What is Data Warehouse](https://www.edureka.co/blog/a-brief-on-data-warehouse/)[Dimension Table in Data Warehousing](https://www.edureka.co/blog/dimension-table-in-data-warehousing/)[Data Warehousing Interview Questions](https://www.edureka.co/blog/interview-questions/data-warehousing-interview-questions-and-answers/)[Data warehouse architecture](https://www.edureka.co/blog/architecture-of-a-data-warehouse/)[Talend Tutorial](https://www.edureka.co/blog/talend-tutorial-data-integration/)[Talend ETL Tool](https://www.edureka.co/blog/talend-etl-tool/)[Talend Interview Questions](https://www.edureka.co/blog/interview-questions/talend-interview-questions/)[Fact Table and its Types](https://www.edureka.co/blog/fact-table-and-its-types-in-data-warehousing/)[Informatica Transformations](https://www.edureka.co/blog/informatica-transformations/)[Informatica Tutorial](https://www.edureka.co/blog/informatica-tutorial)[VIEW ALL](https://www.edureka.co/blog/category/data-warehousing-and-etl/) - [Databases](https://www.edureka.co/blog/python-metaclasses/#show_category_70) [What is MySQL](https://www.edureka.co/blog/what-is-mysql/)[MySQL Data Types](https://www.edureka.co/blog/mysql-data-types/)[SQL Joins](https://www.edureka.co/blog/sql-joins-types)[SQL Data Types](https://www.edureka.co/blog/sql-data-types/)[What is MongoDB](https://www.edureka.co/blog/mongodb-the-database-for-big-data-processing/)[MongoDB Interview Questions](https://www.edureka.co/blog/mongodb-interview-questions-for-beginners-and-professionals)[MySQL Tutorial](https://www.edureka.co/blog/mysql-tutorial/)[SQL Interview Questions](https://www.edureka.co/blog/interview-questions/sql-interview-questions)[SQL Commands](https://www.edureka.co/blog/sql-commands)[MySQL Interview Questions](https://www.edureka.co/blog/interview-questions/mysql-interview-questions/)[VIEW ALL](https://www.edureka.co/blog/category/databases/) - [DevOps](https://www.edureka.co/blog/python-metaclasses/#show_category_80) [What is DevOps](https://www.edureka.co/blog/what-is-devops/)[DevOps vs Agile](https://www.edureka.co/blog/devops-vs-agile-everything-you-need-to-know/)[DevOps Tools](https://www.edureka.co/blog/top-10-devops-tools/)[DevOps Tutorial](https://www.edureka.co/blog/devops-tutorial)[How To Become A DevOps Engineer](https://www.edureka.co/blog/how-to-become-a-devops-engineer/)[DevOps Interview Questions](https://www.edureka.co/blog/interview-questions/top-devops-interview-questions/)[What Is Docker](https://www.edureka.co/blog/what-is-docker-container)[Docker Tutorial](https://www.edureka.co/blog/docker-tutorial)[Docker Interview Questions](https://www.edureka.co/blog/interview-questions/docker-interview-questions/)[What Is Chef](https://www.edureka.co/blog/what-is-chef/)[What Is Kubernetes](https://www.edureka.co/blog/what-is-kubernetes-container-orchestration)[Kubernetes Tutorial](https://www.edureka.co/blog/kubernetes-tutorial/)[VIEW ALL](https://www.edureka.co/blog/category/devops/) - [Front End Web Development](https://www.edureka.co/blog/python-metaclasses/#show_category_79) [What is JavaScript – All You Need To Know About JavaScript](https://www.edureka.co/blog/what-is-javascript/)[JavaScript Tutorial](https://www.edureka.co/blog/javascript-tutorial/)[JavaScript Interview Questions](https://www.edureka.co/blog/interview-questions/javascript-interview-questions/)[JavaScript Frameworks](https://www.edureka.co/blog/top-10-javascript-frameworks/)[Angular Tutorial](https://www.edureka.co/blog/angular-tutorial/)[Angular Interview Questions](https://www.edureka.co/blog/interview-questions/top-angularjs-interview-questions/)[What is REST API?](https://www.edureka.co/blog/what-is-rest-api/)[React Tutorial](https://www.edureka.co/blog/reactjs-tutorial)[React vs Angular](https://www.edureka.co/blog/react-vs-angular)[jQuery Tutorial](https://www.edureka.co/blog/jquery-tutorial/)[Node Tutorial](https://www.edureka.co/blog/nodejs-tutorial/)[React Interview Questions](https://www.edureka.co/blog/interview-questions/react-interview-questions/)[VIEW ALL](https://www.edureka.co/blog/category/front-end-web-development/) - [Mobile Development](https://www.edureka.co/blog/python-metaclasses/#show_category_152) [Android Tutorial](https://www.edureka.co/blog/android-tutorial/)[Android Interview Questions](https://www.edureka.co/blog/interview-questions/top-android-interview-questions-for-beginners/)[Android Architecture](https://www.edureka.co/blog/beginners-guide-android-architecture/)[Android SQLite Database](https://www.edureka.co/blog/introduction-on-android-sqlite-database/)[Programming & Frameworks](https://www.edureka.co/blog/category/programming-and-frameworks/)[Android Adapter Tutorial](https://www.edureka.co/blog/what-are-adapters-in-android/)[Cursor in Android](https://www.edureka.co/blog/introduction-to-cursor-in-android/)[Swift Tutorial](https://www.edureka.co/blog/swift-tutorial)[iOS Interview Questions](https://www.edureka.co/blog/interview-questions/ios-interview-questions/)[VIEW ALL](https://www.edureka.co/blog/category/mobile-development/) - [Operating Systems](https://www.edureka.co/blog/python-metaclasses/#show_category_151) [Linux Tutorial](https://www.edureka.co/blog/linux-tutorial/)[Unix vs Linux](https://www.edureka.co/blog/unix-vs-linux/)[How to Install Ubuntu](https://www.edureka.co/blog/how-to-install-ubuntu/)[Shell Scripting Interviews](https://www.edureka.co/blog/interview-questions/shell-scripting-interview-questions/)[Install JDK on Ubuntu](https://www.edureka.co/blog/how-to-install-java-on-ubuntu/)[Linux Commands](https://www.edureka.co/blog/linux-commands/)[Linux Administrator Responsibilities](https://www.edureka.co/blog/duties-of-a-linux-administrator/)[Linux Career](https://www.edureka.co/blog/linux-making-the-right-career-choice)[Why Learn Shell Scripting](https://www.edureka.co/blog/top-reasons-to-learn-unix-shell-scripting/)[Linux Interview Questions](https://www.edureka.co/blog/interview-questions/linux-interview-questions-for-beginners/)[VIEW ALL](https://www.edureka.co/blog/category/operating-systems/) - [Programming & Frameworks](https://www.edureka.co/blog/python-metaclasses/#show_category_155) [C Programming Tutorial](https://www.edureka.co/blog/c-programming-tutorial/)[Java Tutorial](https://www.edureka.co/blog/java-tutorial/)[Inheritance in Java](https://www.edureka.co/blog/inheritance-in-java/)[Top Java Projects you need to know in 2026](https://www.edureka.co/blog/java-projects)[Java Interview Questions](https://www.edureka.co/blog/interview-questions/java-interview-questions/)[What is the use of Destructor in Java?](https://www.edureka.co/blog/destructor-in-java/)[Polymorphism in Java](https://www.edureka.co/blog/polymorphism-in-java/)[Multithreading in Java](https://www.edureka.co/blog/java-thread/)[All you Need to Know About Implements In Java](https://www.edureka.co/blog/implements-in-java/)[Spring Interview Questions](https://www.edureka.co/blog/interview-questions/spring-interview-questions/)[PHP Tutorial](https://www.edureka.co/blog/php-tutorial-for-beginners/)[PHP Interview Questions](https://www.edureka.co/blog/interview-questions/php-interview-questions/)[Python Tutorial](https://www.edureka.co/blog/python-tutorial/)[Python Interview Questions](https://www.edureka.co/blog/interview-questions/python-interview-questions/)[VIEW ALL](https://www.edureka.co/blog/category/programming-and-frameworks/) - [Project Management and Methodologies](https://www.edureka.co/blog/python-metaclasses/#show_category_154) [PMP Exam](https://www.edureka.co/blog/pmp-exam-all-you-need-to-know/)[Project Management Life Cycle](https://www.edureka.co/blog/project-management-life-cycle/)[Project Manager Interview Questions](https://www.edureka.co/blog/interview-questions/top-project-management-interview-questions/)[Supply Chain Management](https://www.edureka.co/blog/supply-chain-management-101-all-you-need-to-know-about-eSCM)[Project Manager Salary](https://www.edureka.co/blog/project-manager-salary/)[PMP Exam Questions and Answers](https://www.edureka.co/blog/interview-questions/pmp-exam-questions-answers/)[Earned Value Analysis in Project Management (EVA) Formula](https://www.edureka.co/blog/earned_value_analysis_in_project-management/)[Project Management Office Setup](https://www.edureka.co/blog/how-to-set-up-a-project-management-office-in-your-organization)[VIEW ALL](https://www.edureka.co/blog/category/project-management/) - [Robotic Process Automation](https://www.edureka.co/blog/python-metaclasses/#show_category_404) [What Is RPA](https://www.edureka.co/blog/rpa-blue-prism/)[Learn RPA](https://www.edureka.co/blog/10-reasons-to-learn-rpa/)[RPA Tools](https://www.edureka.co/blog/rpa-tools-list-and-comparison/)[Selenium vs RPA](https://www.edureka.co/blog/selenium-vs-rpa/)[RPA Developer Salary](https://www.edureka.co/blog/rpa-developer-salary)[Uipath Orchestrator](https://www.edureka.co/blog/uipath-orchestrator/)[RPA Interview Questions](https://www.edureka.co/blog/interview-questions/rpa-uipath-interview-questions/)[UiPath RPA Architecture](https://www.edureka.co/blog/uipath-rpa-architecture/)[RPA Projects](https://www.edureka.co/blog/rpa-projects)[RPA Lifeycycle](https://www.edureka.co/blog/rpa-lifecycle)[VIEW ALL](https://www.edureka.co/blog/category/robotic-process-automation/) - [Software Testing](https://www.edureka.co/blog/python-metaclasses/#show_category_102) [What is Software Testing](https://www.edureka.co/blog/what-is-software-testing/)[Software Testing Interview Questions](https://www.edureka.co/blog/interview-questions/software-testing-interview-questions/)[Software Testing Life Cycle](https://www.edureka.co/blog/software-testing-life-cycle/)[Types of Software Testing](https://www.edureka.co/blog/types-of-software-testing/)[Selenium Interview Questions](https://www.edureka.co/blog/interview-questions/selenium-interview-questions-answers/)[Selenium Tutorial](https://www.edureka.co/blog/selenium-tutorial)[JMeter Tutorial](https://www.edureka.co/blog/jmeter-tutorial/)[Regression Testing](https://www.edureka.co/blog/regression-testing)[Unit Testing](https://www.edureka.co/blog/what-is-unit-testing)[Automation Testing Tutorial](https://www.edureka.co/blog/automation-testing-tutorial/)[Functional Testing](https://www.edureka.co/blog/what-is-functional-testing/)[Smoke Testing](https://www.edureka.co/blog/what-is-smoke-testing/)[API Testing](https://www.edureka.co/blog/what-is-api-testing)[Integration Testing](https://www.edureka.co/blog/what-is-integration-testing-a-simple-guide-on-how-to-perform-integration-testing/)[Penetration Testing](https://www.edureka.co/blog/what-is-penetration-testing/)[VIEW ALL](https://www.edureka.co/blog/category/software-testing/) 1. [Home](https://www.edureka.co/) 2. [Blog](https://www.edureka.co/blog/) 3. [Data Science](https://www.edureka.co/blog/category/data-science/) 4. [How To Create Your First Pytho...](https://www.edureka.co/blog/python-metaclasses/) Mastering Python (96 Blogs) [Become a Certified Professional](https://www.edureka.co/data-science-python-certification-course) AWS Global Infrastructure ##### Introduction to Python - [Learn Python Programming – One Stop Solution for Beginners](https://www.edureka.co/blog/learn-python/) - [What is Python language? Is it easy to learn?](https://www.edureka.co/blog/what-is-python/) - [Python Tutorial – Python Programming For Beginners](https://www.edureka.co/blog/python-tutorial/) - [Python: Interesting Facts You Need To Know](https://www.edureka.co/blog/python-interesting-facts-you-need-to-know/) - [Which are the best books for Python?](https://www.edureka.co/blog/best-books-for-python/) - [Top 10 Features of Python You Need to Know](https://www.edureka.co/blog/python-features/) - [Top 10 Python Applications in the Real World You Need to Know](https://www.edureka.co/blog/python-applications/) - [Python Anaconda Tutorial : Everything You Need To Know](https://www.edureka.co/blog/python-anaconda-tutorial/) - [Top 10 Reasons Why You Should Learn Python](https://www.edureka.co/blog/10-reasons-why-you-should-learn-python) - [What are Important Advantages and Disadvantages Of Python?](https://www.edureka.co/blog/advantages-and-disadvantages-of-python/) - [Python and Netflix: What Happens When You Stream a Film?](https://www.edureka.co/blog/how-netflix-uses-python/) - [How to Learn Python 3 from Scratch – A Beginners Guide](https://www.edureka.co/blog/learn-python-3/) - [Top 10 Best IDE for Python: How to choose the best Python IDE?](https://www.edureka.co/blog/best-ide-for-python/) - [How To Use Python For DevOps?](https://www.edureka.co/blog/python-devops/) - [Python vs C: Know what are the differences](https://www.edureka.co/blog/python-vs-c/) - [Python vs C++: Know what are the differences](https://www.edureka.co/blog/python-vs-cpp/) - [Ruby vs Python : What are the Differences?](https://www.edureka.co/blog/ruby-vs-python/) ##### Python Installation - [Install Python On Windows – Python 3.X Installation Guide](https://www.edureka.co/blog/install-python-on-windows/) - [How To Run Python In Ubuntu (Linux)?](https://www.edureka.co/blog/run-python-in-ubuntu-linux/) - [What is Python Spyder IDE and How to use it?](https://www.edureka.co/blog/spyder-ide/) - [How To Add Python to Path?](https://www.edureka.co/blog/add-python-to-path/) - [Introduction to Atom Python Text Editor and how to configure it](https://www.edureka.co/blog/atom-python-ide/) - [Python 101 : Hello World Program](https://www.edureka.co/blog/python-101-hello-world-program/) ##### Python Fundamentals - [Python Basics: What makes Python so Powerful?](https://www.edureka.co/blog/python-basics/) - [Data Structures You Need To Learn In Python](https://www.edureka.co/blog/data-structures-in-python/) - [What is the use of self in Python?](https://www.edureka.co/blog/self-in-python/) - [Python Programming – Beginners Guide To Python Programming Language](https://www.edureka.co/blog/python-programming-language) - [What is print in Python and How to use its Parameters?](https://www.edureka.co/blog/print-in-python/) - [Important Python Data Types You Need to Know](https://www.edureka.co/blog/python-data-types/) - [PyCharm Tutorial: Writing Python Code In PyCharm (IDE)](https://www.edureka.co/blog/pycharm-tutorial) - [Python Visual Studio- Learn How To Make Your First Python Program](https://www.edureka.co/blog/python-visual-studio/) - [What is the Main Function in Python and how to use it?](https://www.edureka.co/blog/python-main-function/) - [What is Try Except in Python and how it works?](https://www.edureka.co/blog/python-try-except/) - [What are Comments in Python and how to use them?](https://www.edureka.co/blog/comments-in-python/) - [How to fetch and modify Date and Time in Python?](https://www.edureka.co/blog/date-time-in-python/) - [Inheritance In Python With Examples: All You Need To Know](https://www.edureka.co/blog/inheritance-in-python/) - [How To Best Utilize Python CGI In Day To Day Coding?](https://www.edureka.co/blog/python-cgi/) - [Python Constructors: Everything You Need To Know](https://www.edureka.co/blog/python-constructors/) - [How To Create Your First Python Metaclass?](https://www.edureka.co/blog/python-metaclasses/) - [Init In Python: Everything You Need To Know](https://www.edureka.co/blog/init-in-python/) - [Learn How To Use Split Function In Python](https://www.edureka.co/blog/split-function-in-python/) - [How to Read CSV File in Python?](https://www.edureka.co/blog/python-csv-files/) - [Stack in Python: How, why and where?](https://www.edureka.co/blog/stack-in-python/) - [Hash Tables and Hashmaps in Python: What are they and How to implement?](https://www.edureka.co/blog/hash-tables-and-hashmaps-in-python/) - [What is Random Number Generator in Python and how to use it?](https://www.edureka.co/blog/generate-random-number-in-python/) - [How to find Square Root in Python?](https://www.edureka.co/blog/square-root-in-python/) - [Arrays in Python – What are Python Arrays and how to use them?](https://www.edureka.co/blog/arrays-in-python/) - [Loops In Python: Why Should You Use One?](https://www.edureka.co/blog/loops-in-python/) - [What are Sets in Python and How to use them?](https://www.edureka.co/blog/sets-in-python/) - [What is Method Overloading in Python and How it Works?](https://www.edureka.co/blog/python-method-overloading/) - [Python Functions : A Complete Beginners Guide](https://www.edureka.co/blog/python-functions) - [Learn How To Use Map Function In Python With Examples](https://www.edureka.co/blog/map-function-in-python/) - [Python time sleep() – One Stop Solution for time.sleep() Method](https://www.edureka.co/blog/python-time-sleep/) - [How To Reverse A String In Python?](https://www.edureka.co/blog/how-to-reverse-a-string-in-python/) - [How To Sort A Dictionary In Python : Sort By Keys , Sort By Values](https://www.edureka.co/blog/how-to-sort-a-dictionary-in-python/) - [String Function In Python: How To Use It with Examples](https://www.edureka.co/blog/what-is-string-in-python/) - [How To Convert Decimal To Binary In Python](https://www.edureka.co/blog/decimal-to-binary-in-python/) - [Python Tuple With Example: Everything You Need To Know](https://www.edureka.co/blog/tuple-in-python/) - [How To Input a List in Python?](https://www.edureka.co/blog/input-a-list-in-python/) - [How to Find Length of List in Python?](https://www.edureka.co/blog/python-list-length/) - [How to Reverse a List in Python: Learn Python List Reverse() Method](https://www.edureka.co/blog/python-reverse-list/) - [Learn What is Range in Python With Examples](https://www.edureka.co/blog/range-in-python/) - [Everything You Need To Know About Hash In Python](https://www.edureka.co/blog/hash-in-python/) - [What Isinstance In Python And How To Implement It?](https://www.edureka.co/blog/isinstance-in-python/) - [How To Best Implement Armstrong Number In Python?](https://www.edureka.co/blog/armstrong-number-in-python/) - [How To Implement Round Function In Python?](https://www.edureka.co/blog/round-function-in-python/) - [How To Implement 2-D arrays in Python?](https://www.edureka.co/blog/2d-arrays-in-python/) - [Learn How To Make Python Pattern Programs With Examples](https://www.edureka.co/blog/python-pattern-programs/) - [Introduction To File Handling In Python](https://www.edureka.co/blog/file-handling-in-python/) - [What is Python JSON and How to implement it?](https://www.edureka.co/blog/python-json/) - [Threading In Python: Learn How To Work With Threads In Python](https://www.edureka.co/blog/threading-in-python/) - [How To Best Implement Multiprocessing In Python?](https://www.edureka.co/blog/multiprocessing-in-python/) - [Know all About Robot Framework With Python](https://www.edureka.co/blog/robot-framework-tutorial/) - [What is Mutithreading in Python and How to Achieve it?](https://www.edureka.co/blog/what-is-mutithreading/) - [Map, Filter and Reduce Functions in Python: All you need to know](https://www.edureka.co/blog/function-map-filter-reduce/) - [What is the Format Function in Python and How does it work?](https://www.edureka.co/blog/format-function-in-python/) - [Python Database Connection: Know how to connect with database](https://www.edureka.co/blog/python-database-connection/) - [What are Lambda Functions and How to Use Them?](https://www.edureka.co/blog/python-lambda/) - [What are Generators in Python and How to use them?](https://www.edureka.co/blog/generators-in-python/) - [Python Iterators: What is Iterator in Python and how to use it?](https://www.edureka.co/blog/python-iterator) - [Python For Loop Tutorial With Examples To Practice](https://www.edureka.co/blog/python-for-loop/) - [While Loop In Python : All You Need To Know](https://www.edureka.co/blog/while-loop-in-python/) - [What is Socket Programming in Python and how to master it?](https://www.edureka.co/blog/socket-programming-python/) - [Regular Expression in Python With Example](https://www.edureka.co/blog/python-regex/) - [How to Parse and Modify XML in Python?](https://www.edureka.co/blog/python-xml-parser-tutorial/) ##### Python OOPs - [Object Oriented Programming Python: All you need to know](https://www.edureka.co/blog/object-oriented-programming-python/) - [Python Class – Object Oriented Programming](https://www.edureka.co/blog/python-class/) - [What is Polymorphism in OOPs programming?](https://www.edureka.co/blog/polymorphism-in-python/) - [Python String Concatenation : Everything You Need To Know](https://www.edureka.co/blog/python-string-concatenation/) - [Everything You Need To Know About Print Exception In Python](https://www.edureka.co/blog/print-exception-in-python/) ##### Python Libraries - [Top Python Libraries You Must Know In 2025](https://www.edureka.co/blog/python-libraries/) - [How To Install NumPy In Python?](https://www.edureka.co/blog/install-numpy/) - [Python NumPy Tutorial – Introduction To NumPy With Examples](https://www.edureka.co/blog/python-numpy-tutorial/) - [Python Pandas Tutorial : Learn Pandas for Data Analysis](https://www.edureka.co/blog/python-pandas-tutorial/) - [Python Matplotlib Tutorial – Data Visualizations In Python With Matplotlib](https://www.edureka.co/blog/python-matplotlib-tutorial/) - [Python Seaborn Tutorial: What is Seaborn and How to Use it?](https://www.edureka.co/blog/python-seaborn-tutorial/) - [SciPy Tutorial: What is Python SciPy and How to use it?](https://www.edureka.co/blog/scipy-tutorial/) - [How To Make A Chatbot In Python?](https://www.edureka.co/blog/how-to-make-a-chatbot-in-python/) - [FIFA World Cup 2018 Best XI: Analyzing Fifa Dataset Using Python](https://www.edureka.co/blog/football-world-cup-best-xi-analysis-using-python/) - [Scikit learn – Machine Learning using Python](https://www.edureka.co/blog/scikit-learn-machine-learning/) - [The Why And How Of Exploratory Data Analysis In Python](https://www.edureka.co/blog/exploratory-data-analysis-in-python/) - [OpenCV Python Tutorial: Computer Vision With OpenCV In Python](https://www.edureka.co/blog/python-opencv-tutorial/) - [Tkinter Tutorial For Beginners \| GUI Programming Using Tkinter In Python](https://www.edureka.co/blog/tkinter-tutorial/) - [Introduction To Game Building With Python's Turtle Module](https://www.edureka.co/blog/python-turtle-module/) - [PyGame Tutorial – Game Development Using PyGame In Python](https://www.edureka.co/blog/pygame-tutorial) - [PyTorch Tutorial – Implementing Deep Neural Networks Using PyTorch](https://www.edureka.co/blog/pytorch-tutorial/) - [Scrapy Tutorial: How To Make A Web-Crawler Using Scrapy?](https://www.edureka.co/blog/scrapy-tutorial/) ##### Web Scraping - [A Beginner's Guide to learn web scraping with python\!](https://www.edureka.co/blog/web-scraping-with-python/) - [Python Requests Module Tutorial – Sending HTTP Requests Using Requests Module](https://www.edureka.co/blog/python-requests-tutorial/) ##### Django - [Django Tutorial – Web Development with Python Django Framework](https://www.edureka.co/blog/django-tutorial/) - [Django vs Flask: Which is the best for your Web Application?](https://www.edureka.co/blog/django-vs-flask/) - [Top 50 Django Interview Questions and Answers You Need to Know in 2025](https://www.edureka.co/blog/interview-questions/django-interview-questions/) ##### Python Programs - [Palindrome in Python: How to Check a Number or String is Palindrome?](https://www.edureka.co/blog/python-program-to-check-palindrome/) - [How to Find Prime Numbers in Python](https://www.edureka.co/blog/python-program-prime-number/) - [How To Implement GCD In Python?](https://www.edureka.co/blog/gcd-in-python/) - [How To Convert Lists To Strings In Python?](https://www.edureka.co/blog/convert-list-to-string/) - [How to Display Fibonacci Series in Python?](https://www.edureka.co/blog/python-fibonacci-series/) - [How to implement Python program to check Leap Year?](https://www.edureka.co/blog/python-program-to-check-leap-year/) - [How to reverse a number in Python?](https://www.edureka.co/blog/how-to-reverse-a-number/) - [How to Implement a Linked List in Python?](https://www.edureka.co/blog/linked-list-in-python/) - [How to implement Bubble Sort in Python?](https://www.edureka.co/blog/python-program-bubble-sort) - [How to implement Merge Sort in Python?](https://www.edureka.co/blog/python-program-merge-sort/) - [A 101 Guide On The Least Squares Regression Method](https://www.edureka.co/blog/least-square-regression/) ##### Career Oppurtunities - [Python Career Opportunities: Your Career Guide To Python Programming](https://www.edureka.co/blog/python-career-opportunities-your-guide-to-a-career-in-python-programming) - [Top Python developer Skills you need to know](https://www.edureka.co/blog/python-developer-skills/) - [Learn How To Make A Resume For A Python Developer](https://www.edureka.co/blog/python-developer-resume/) - [What is the Average Python Developer Salary?](https://www.edureka.co/blog/python-developer-salary/) - [How To Become A Python Developer : Learning Path For Python](https://www.edureka.co/blog/how-to-become-a-python-developer/) - [Why You Should Choose Python For Big Data](https://www.edureka.co/blog/why-you-should-choose-python-for-big-data) ##### Interview Questions - [Python Interview Questions](https://www.edureka.co/blog/interview-questions/python-interview-questions/) - [Top 50 OOPs Interview Questions and Answers in 2025](https://www.edureka.co/blog/interview-questions/oops-interview-questions/) - [Top Python Projects You Should Consider Learning](https://www.edureka.co/blog/python-projects/) ### Data Science Topics Covered - Business Analytics with R (27 Blogs) - Data Science (22 Blogs) - Mastering Python (90 Blogs) - Decision Tree Modeling Using R (1 Blogs) [SEE MORE Data Science blog posts](https://www.edureka.co/blog/category/data-science/) # How To Create Your First Python Metaclass? Last updated on Nov 28,2024 4.1K Views Share [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2030%2030'%3E%3C/svg%3E)![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/whatsapp.png)WhatsApp](https://api.whatsapp.com/send?phone&text=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F%20%20https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dwhatsapp%20%20%23Edureka&app_absent=0) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2030%2030'%3E%3C/svg%3E)![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/linkedin.png)Linkedin](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dlinkedin&title=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F&summary=How%20To%20Create%20Your%20First%20Python%20Metaclass%3Fhttps%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dlinkedin%23Edureka&source=https%3A%2F%2Fwww.edureka.co%2Fblog) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2030%2030'%3E%3C/svg%3E)![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/twitter.png)Twitter](https://twitter.com/intent/tweet?text=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F%20%20%23Edureka&url=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dtwitter&via=edurekain%20#Edureka) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2030%2030'%3E%3C/svg%3E)![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/facebook.png)Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dfacebook&quote=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F%20%20https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dfacebook%20%20%23Edureka) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2030%2030'%3E%3C/svg%3E)![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/reddit.png)Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dreddit&title=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F) ![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2030%2030'%3E%3C/svg%3E) ![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/feather_link.png) Copy Link\! ![](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==) [Aishwarya](https://www.edureka.co/blog/author/aishwarya-senedureka-co/ "Post By Aishwarya") - [Bookmark](https://www.edureka.co/blog/python-metaclasses/) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/whatsapp.png)](https://api.whatsapp.com/send?phone&text=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F%20%20https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dwhatsapp%20%20%23Edureka&app_absent=0) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/linkedin.png)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dlinkedin&title=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F&summary=How%20To%20Create%20Your%20First%20Python%20Metaclass%3Fhttps%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dlinkedin%23Edureka&source=https%3A%2F%2Fwww.edureka.co%2Fblog) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/twitter.png)](https://twitter.com/intent/tweet?text=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F%20%20%23Edureka&url=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dtwitter&via=edurekain%20#Edureka) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/facebook.png)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dfacebook&quote=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F%20%20https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dfacebook%20%20%23Edureka) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/reddit.png)](https://www.reddit.com/submit?url=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dreddit&title=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F) ![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E) ![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/feather_link.png) Copy Link\! 16 / 62 Blog from Python Fundamentals *** [Become a Certified Professional](https://www.edureka.co/data-science-python-certification-course) A Python Metaclass sets the behavior and rules of a class. Metaclass helps in modifying the instantiation of a class and is fairly complex and one of the advanced features of Python programming. Through this article, I will be discussing in-depth concepts of Python Metaclass, its properties, how and when to use a Metaclass in Python. This article covers the following concepts: Table of Content 1. [What is Python Metaclass?](https://www.edureka.co/blog/python-metaclasses/#what-is-python-metaclass "What is Python Metaclass?") 2. [Classes and Objects in Python](https://www.edureka.co/blog/python-metaclasses/#classes-and-objects-in-python "Classes and Objects in Python") 3. [Dynamic Class in Python](https://www.edureka.co/blog/python-metaclasses/#dynamic-class-in-python "Dynamic Class in Python") 4. [How Does Python Metaclass Work?](https://www.edureka.co/blog/python-metaclasses/#how-does-python-metaclass-work "How Does Python Metaclass Work?") 5. [Decorator vs Metaclass](https://www.edureka.co/blog/python-metaclasses/#decorator-vs-metaclass "Decorator vs Metaclass") ## **What is Python Metaclass?** Python Metaclass is one of the advanced features associated with [Object-Oriented Programming concepts](https://www.edureka.co/blog/object-oriented-programming-python/) of Python. It determines the behavior of a class and further helps in its modification. ![Metaclass hierarchy - Python Metaclass - Edureka](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20872%20387'%3E%3C/svg%3E) ![Metaclass hierarchy - Python Metaclass - Edureka](https://www.edureka.co/blog/wp-content/uploads/2020/07/final.png) Every class created in Python has an underlying Metaclass. So when you’re creating a class, you are indirectly using the Metaclass. It happens implicitly, you don’t need to specify anything. Metaclass when associated with metaprogramming determines the ability of a program to manipulate itself. Learning Metaclass might seem complex but let’s get a few concepts of [classes and objects](https://www.edureka.co/blog/python-class/) out of the way first, so that it’s simple to understand. ## **Classes and Objects in Python** A class is a blueprint, a logical entity having objects. A simple class when declared does not have any memory allocated, it happens when an instance of a class is created. Through the objects created, one can access the class. The class simply works as a template. The property of an object essentially means that we can interact with it at runtime, pass parameters like variables, store, modify, and can also interact with it. The class of an object can be checked by using the \_\_class\_\_ attribute. Let’s see this simple example: ``` class Demo: pass #This is a class named demo test=Demo() print(test.__class__) #shows class of obj print(type(test)) #alternate method ``` `Output: <class '__main__.Demo'>` Python heavily deals with the concept of classes and objects and allows easy and smooth application development. But what makes [Python](https://www.edureka.co/blog/learn-python/) different from languages like [Java](https://www.edureka.co/blog/java-tutorial/) and [C](https://www.edureka.co/blog/c-programming-tutorial/)? ***Everything in Python can be defined as an object having attributes and methods.*** Keynote is that classes in Python are nothing but another object of a bigger class. ~~![Instances of metaclass - Python metaclass - Edureka](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)~~ A class defines rules for an object. Similarly, a Metaclass is responsible for assigning behaviors for the classes. We have learned that Class is an object, and like every object has an instance, a class is an instance of a Metaclass. But there are languages like [Ruby](https://www.edureka.co/blog/ruby-on-rails-tutorial/) and Objective-C which support Metaclasses as well. So, what makes Python Metaclass better and why should you learn it? The answer is the dynamic class in Python. Let’s take a closer look at it. ## **Dynamic Class in Python** Python is a dynamic programming language and allows the creation of a class at runtime. Unlike other languages like C++, which only allows the class creation at compile time. In terms of flexibility, Python has an advantage over other languages that are statically typed. The difference between dynamic and statically typed language isn’t much, but in Python, it becomes more useful because it provides metaprogramming. But what if I tell you that there’s another key feature that distinguishes Python from other programming languages? Languages like Java or [C++](https://www.edureka.co/blog/cpp-tutorial/) have data types like float, char, int, etc. whereas Python treats each variable as an object. And each object belongs to a class like an int class or str class. You can simply check the class of any variable using a built-in function called **type().** ``` number = 10993 print("Type associated is:", type(number)) name = "Aishwarya" print("Type associated is:", type(name)) ``` `Output: ` `Type associated is:  <class 'int'>` `Type associated is: <class 'str'>` Now that you understand everything in Python has a type associated with it. In the next topic, we will try to understand how Metaclass actually works. ## **How Does Python Metaclass Work?** Whenever a class is created the default Metaclass which is type class gets called instead. Metaclass carries information like name, set of a base class, and attributes associated with the class. Hence, when a class is instantiated type class is called carrying these arguments. Metaclass can be created via two methods: 1. Type class 2. Custom Metaclass Let’s move on to type class and how you can create one. ### **Type Class** Python has a built-in Metaclass called type. Unlike Java or C, where there are primary data types. Every variable or object in Python has a class associated with it. Python use Type class behind-the-scenes to create all the classes. In the previous topic, we saw how we can check the class of an object by using **type().** Let’s take an example of how we can define a new type, by creating a simple class. ``` class Edureka(): obj = Edureka() print(type(obj)) ``` `Output: <class '__main__.Edureka'>` ``` print(type(Edureka)) ``` `Output: <class 'type'>` In the above code, we have a class called Edureka, and an object associated. We created a new type called Edureka by simply creating a class named itself after the type. In the second code, when we check the type of Edureka class, it results as ‘type’. So, unless defined otherwise, Metaclasses use **type class** to create all the other classes. We can access Type class via two methods: ![methods to use type class - Python metaclass - Edureka](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==) When we pass parameters through type class, it uses the following syntax. ``` type(__name__, __base__, attributes) ``` where, - the name is a string and carries the class name - the base is a tuple and helps create subclasses - an attribute is a dictionary and assigns key-value pairs Since classes in Python behave similar to the objects, their behavior could be altered in the same way. We can add or remove methods within a class similar to how we do with objects. Now that you know Metaclass creates all the other classes in Python and defines their behavior using type class. But then you must be wondering, is there any other way we can create Metaclass? So, let’s see how to create a custom Metaclass that. Ready to unlock the power of data? Dive into [Python for Data Science](https://www.edureka.co/data-science-python-certification-course) today! Whether you’re analyzing trends, building predictive models, or extracting valuable insights, Python’s versatile libraries like NumPy, pandas, and scikit-learn empower you to conquer any data challenge ### **Custom Metaclass in Python** Now that we know and understand how the type class works. It’s time to learn how we can create our custom Metaclass. We can modify the working of classes by carrying actions or code injection. To achieve this, we can pass Metaclass as a keyword while creating a class definition. Alternatively, we can achieve this by simply inheriting a class that has been instantiated through this Metaclass keyword. At the time of creating a new class, Python looks for the **\_\_metaclass\_\_** keyword. In case, if it isn’t present. It follows the type class hierarchy. ![custom type class hierarchy - Python metaclass - Edureka](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==) After Python executes all the dictionary in a namespace, it invokes type object which creates objects of a class. There are two methods that we can use to create custom Metaclass. ``` custom metaclass methods - Python metaclass - Edureka ``` ``` class EduFirst(type): def __new__(cls, name, base_cls, dict): pass class EduSecond(type): def __init__(self, name, base_cls, dict): pass ``` Let me explain these two methods in detail: 1. **\_\_new\_\_():** is used when a user wants to define a dictionary of tuples before the class creation. It returns an instance of a class and is easy to override/manage the flow of objects. 2. **\_\_init\_\_()**: It’s called after the object has already been created and simply initializes it. ### **What is \_\_call\_\_ in Python?** In the official [Python documents](https://docs.python.org/3/tutorial/index.html), the **\_\_call\_\_** method can be used to define a custom Metaclass. Also, we can override other methods like \_\_prepare\_\_ when calling a class to define custom behavior. Much like how a class behaves like a template to create objects, in the same way, Metaclass acts like a template for the class creation. Therefore, a Metaclass is also known as a class factory. See the next example: ``` class Meta(type): def __init__(cls, name, base, dct): cls.attribute = 200 class Test(metaclass = Meta): pass Test.attribute ``` `Output: 200` Metaclass allows class customization. There are various other effective and much simpler ways through which the same output can be achieved. One such example is using Decorators. ## **Decorator vs Metaclass** [Decorator](https://www.edureka.co/blog/python-decorator-tutorial/) is a popular feature of Python which allows you to add more functionality to the code. A decorator is a callable object which helps modify the existing class or even a function. During compilation, part of code calls and modifies another part. This process is also known as metaprogramming. | | | |---|---| | **Decorator** | **Metaclass** | | Returns the same class after making changes (e.g.: monkey-patching) | We use Metaclass whenever a new class is created | | Lacks flexibility | Provides flexibility and customization of classes | | Isn’t compatible to perform subclassing | Provides subclassing by using inheritance and converting object methods to static methods for better optimization | ``` def decorator(cls): class NewClass(cls): attribute = 200 return NewClass @decorator Class Test1: pass @decorator Class Test2: pass Test1.attribute Test2.attribute ``` `Output: 200` [Decorator in Python](https://www.edureka.co/blog/decorators-in-python/) is a very useful and powerful tool that helps change the behavior of a function without actually changing any of the code. This comes handy when you want to modify a part of the program while debugging, instead of rewriting the function or changing the entire program. Instead, you can simply write a single line decorator and it will take care of the rest. This brings us to the end of the session. Hopefully, this article helped you understand what is Metaclass and how and when to use it. *If you found this article on “Python Metaclass” relevant, check out [Edureka’s Python Programming Certification Course](https://www.edureka.co/python-programming-certification-training) a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.* *We are here to help you with every step on your journey and come up with a curriculum that is designed for students and professionals who want to be a [Python developer](https://www.edureka.co/blog/how-to-become-a-python-developer/). The course is designed to give you a head start into Python programming and train you for both core and advanced Python concepts along with various [Python frameworks](https://www.edureka.co/blog/python-frameworks/) like [Django.](https://www.edureka.co/blog/django-tutorial/)* *If you come across any questions, feel free to ask all your questions in the comments section of “Python Metaclass”. Our team will be glad to answer.* ### Recommended videos for you [![android-development-using-android-5-0-lollipop.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/android-development-using-android-5-0-lollipop-2/) ### Android Development : Using Android 5.0 Lollipop [Watch Now](https://www.edureka.co/blog/videos/android-development-using-android-5-0-lollipop-2/) [![know-the-science-behind-product-recommendation-with-r-programming.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/science-behind-product-recommendation-with-r-programming/) ### Know The Science Behind Product Recommendation With R Programming [Watch Now](https://www.edureka.co/blog/videos/science-behind-product-recommendation-with-r-programming/) [![linear-regression-with-r.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/linear-regression-with-r/) ### Linear Regression With R [Watch Now](https://www.edureka.co/blog/videos/linear-regression-with-r/) [![Python-Loops-Tutorial-Python-For-Loop-While-Loop-Python-Python-Training-Edureka.jpeg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/python-loops/) ### Python Loops – While, For and Nested Loops in Python Programming [Watch Now](https://www.edureka.co/blog/videos/python-loops/) [![3-scenarios-where-predictive-analytics-is-a-must.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/3-scenarios-where-predictive-analytics-is-a-must/) ### 3 Scenarios Where Predictive Analytics is a Must [Watch Now](https://www.edureka.co/blog/videos/3-scenarios-where-predictive-analytics-is-a-must/) [![introduction-to-business-analytics-with-r.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/introduction-business-analytics-with-r/) ### Introduction to Business Analytics with R [Watch Now](https://www.edureka.co/blog/videos/introduction-business-analytics-with-r/) [![the-whys-and-hows-of-predictive-modelling-i.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/the-whys-and-hows-of-predictive-modelling/) ### The Whys and Hows of Predictive Modelling-I [Watch Now](https://www.edureka.co/blog/videos/the-whys-and-hows-of-predictive-modelling/) [![data-science-make-smarter-business-decisions.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/data-science-make-smarter-business-decisions/) ### Data Science : Make Smarter Business Decisions [Watch Now](https://www.edureka.co/blog/videos/data-science-make-smarter-business-decisions/) [![Python-NumPy-Tutorial-NumPy-Array-Python-Tutorial-For-Beginners-Python-Training-Edureka.jpeg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/python-numpy-tutorial/) ### Python Numpy Tutorial – Arrays In Python [Watch Now](https://www.edureka.co/blog/videos/python-numpy-tutorial/) [![Python-Lists-Python-Tuples-Python-Sets-Dictionary-Python-Strings-Python-Training-Edureka.jpeg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/python-list-tuple-string-set-dictonary/) ### Python List, Tuple, String, Set And Dictonary – Python Sequences [Watch Now](https://www.edureka.co/blog/videos/python-list-tuple-string-set-dictonary/) [![business-analytics-decision-tree-in-r.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/business-analytics-decision-tree-in-r/) ### Business Analytics Decision Tree in R [Watch Now](https://www.edureka.co/blog/videos/business-analytics-decision-tree-in-r/) [![Python-Tutorial-Python-Tutorial-for-Beginners-Python-Training-Edureka.jpeg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/python-tutorial/) ### Python Tutorial – All You Need To Know In Python Programming [Watch Now](https://www.edureka.co/blog/videos/python-tutorial/) [![python-for-big-data-analytics.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/python-for-big-data-analytics/) ### Python for Big Data Analytics [Watch Now](https://www.edureka.co/blog/videos/python-for-big-data-analytics/) [![the-whys-and-hows-of-predictive-modeling-ii.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/the-whys-and-hows-of-predictive-modelling-ii/) ### The Whys and Hows of Predictive Modeling-II [Watch Now](https://www.edureka.co/blog/videos/the-whys-and-hows-of-predictive-modelling-ii/) [![mastering-python-an-excellent-tool-for-web-scraping-and-data-analysis.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/python-tool-for-web-scraping-and-data-analysis/) ### Mastering Python : An Excellent tool for Web Scraping and Data Analysis [Watch Now](https://www.edureka.co/blog/videos/python-tool-for-web-scraping-and-data-analysis/) [![Python-Programming-Learn-Python-Python-Tutorial-Python-Training-Edureka.jpeg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/python-programming/) ### Python Programming – Learn Python Programming From Scratch [Watch Now](https://www.edureka.co/blog/videos/python-programming/) [![Python-Class-Python-Classes-Python-Programming-Python-Tutorial-Edureka.jpeg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/python-classes/) ### Python Classes – Python Programming Tutorial [Watch Now](https://www.edureka.co/blog/videos/python-classes/) [![diversity-of-python-programming.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/26622/) ### Diversity Of Python Programming [Watch Now](https://www.edureka.co/blog/videos/26622/) [![web-scraping-and-analytics-with-python.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/web-scraping-and-analytics-with-python/) ### Web Scraping And Analytics With Python [Watch Now](https://www.edureka.co/blog/videos/web-scraping-and-analytics-with-python/) [![Python-Machine-Learning-Tutorial-Machine-Learning-Algorithms-Python-Training-Edureka.jpeg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/videos/python-machine-learning/) ### Machine Learning with Python [Watch Now](https://www.edureka.co/blog/videos/python-machine-learning/) ### Recommended blogs for you [![no-image-1.png](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/data-analyst-skills/) ### 7 In-Demand Data Analyst Skills to Get You Hired in 2026 [Read Article](https://www.edureka.co/blog/data-analyst-skills/) [![Decision\_blog-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/decision-trees/) ### Decision Tree: How To Create A Perfect Decision Tree? [Read Article](https://www.edureka.co/blog/decision-trees/) [![Prime-Number-program-in-python-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/python-program-prime-number/) ### How to Find Prime Numbers in Python [Read Article](https://www.edureka.co/blog/python-program-prime-number/) [![Whats-New-In-Python-3.8--300x175.png](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/whats-new-python-3-8/) ### A Quick Guide To Learn What’s New In Python 3.8 [Read Article](https://www.edureka.co/blog/whats-new-python-3-8/) [![naive-bayes-tutorial-300x175.png](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/naive-bayes-tutorial/) ### Naive Bayes Classifier: Learning Naive Bayes with Python [Read Article](https://www.edureka.co/blog/naive-bayes-tutorial/) [![datasc-adv-datasc-trainingimg1-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/advantages-of-data-science-training/) ### Advantages of Data Science Training [Read Article](https://www.edureka.co/blog/advantages-of-data-science-training/) [![Comments-in-Python-1-300x165.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/comments-in-python/) ### What are Comments in Python and how to use them? [Read Article](https://www.edureka.co/blog/comments-in-python/) [![Isinstance-in-Python-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/isinstance-in-python/) ### What Is Isinstance In Python And How To Implement It? [Read Article](https://www.edureka.co/blog/isinstance-in-python/) [![blog\_Data-Analyst-Roles-and-Responsibilities-1-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/data-analyst-roles-and-responsibilities/) ### Data Analyst Roles and Responsibilities : All You Need to Know [Read Article](https://www.edureka.co/blog/data-analyst-roles-and-responsibilities/) [![Round-Function-In-Python-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/round-function-in-python/) ### How To Implement Round Function In Python? [Read Article](https://www.edureka.co/blog/round-function-in-python/) [![Inheritance-in-Python-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/inheritance-in-python/) ### Inheritance In Python With Examples: All You Need To Know [Read Article](https://www.edureka.co/blog/inheritance-in-python/) [![Python-compressor-300x175.png](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/python-interesting-facts-you-need-to-know/) ### Python: Interesting Facts You Need To Know [Read Article](https://www.edureka.co/blog/python-interesting-facts-you-need-to-know/) [![Zip-Function-in-Python-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/zip-function-in-python/) ### What is Zip and UnZip Function in Python? [Read Article](https://www.edureka.co/blog/zip-function-in-python/) [![Python-XML-Parsing-Tutorial-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/python-xml-parser-tutorial/) ### How to Parse and Modify XML in Python? [Read Article](https://www.edureka.co/blog/python-xml-parser-tutorial/) [![python-programs-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/python-programs/) ### Python Programs: Which Python Fundamentals One Should Focus On? [Read Article](https://www.edureka.co/blog/python-programs/) [![no-image-1.png](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/who-uses-r/) ### Who uses R? [Read Article](https://www.edureka.co/blog/who-uses-r/) [![no-image-1.png](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/data-science-modelling/) ### Data Science Modeling: Key Steps and Best Practices [Read Article](https://www.edureka.co/blog/data-science-modelling/) [![Data-Science-vs-Machine-Learning-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/data-science-vs-machine-learning/) ### Data Science vs Machine Learning – What’s The Difference? [Read Article](https://www.edureka.co/blog/data-science-vs-machine-learning/) [![python-pattern-programs-300x175.png](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/python-pattern-programs/) ### Learn How To Make Python Pattern Programs With Examples [Read Article](https://www.edureka.co/blog/python-pattern-programs/) [![sentiment-analysis-methology-300x175.jpg](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)](https://www.edureka.co/blog/sentiment-analysis-methodology/) ### Sentiment Analysis Methodology [Read Article](https://www.edureka.co/blog/sentiment-analysis-methodology/) Comments 0 Comments ### Join the discussion[Cancel reply](https://www.edureka.co/blog/python-metaclasses/#respond) ### Trending Courses in Data Science [![Data Science with Python Certification Course](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==)Data Science with Python Certification Course 131k Enrolled Learners Weekend Live Class Reviews 5 (49300)](https://www.edureka.co/data-science-python-certification-course) ### Browse Categories [Artificial Intelligence](https://www.edureka.co/blog/category/artificial-intelligence/ "Artificial Intelligence Blogs")[AWS](https://www.edureka.co/blog/category/aws/ "AWS Blogs")[BI and Visualization](https://www.edureka.co/blog/category/business-intelligence/ "BI and Visualization Blogs")[Big Data](https://www.edureka.co/blog/category/big-data-analytics/ "Big Data Blogs")[Blockchain](https://www.edureka.co/blog/category/blockchain/ "Blockchain Blogs")[Business Management](https://www.edureka.co/blog/category/business-management/ "Business Management Blogs")[Cloud Computing](https://www.edureka.co/blog/category/cloud-computing/ "Cloud Computing Blogs")[Cyber Security](https://www.edureka.co/blog/category/cyber-security/ "Cyber Security Blogs")[Data Warehousing and ETL](https://www.edureka.co/blog/category/data-warehousing-and-etl/ "Data Warehousing and ETL Blogs")[Databases](https://www.edureka.co/blog/category/databases/ "Databases Blogs")[DevOps](https://www.edureka.co/blog/category/devops/ "DevOps Blogs")[Digital Marketing](https://www.edureka.co/blog/category/digital-marketing/ "Digital Marketing Blogs")[Enterprise](https://www.edureka.co/blog/category/enterprise/ "Enterprise Blogs")[Front End Web Development](https://www.edureka.co/blog/category/front-end-web-development/ "Front End Web Development Blogs")[Human Resource Management](https://www.edureka.co/blog/category/human-resource-management/ "Human Resource Management Blogs")[Interview Questions](https://www.edureka.co/blog/category/interview-questions/ "Interview Questions Blogs")[Mobile Development](https://www.edureka.co/blog/category/mobile-development/ "Mobile Development Blogs")[Operating Systems](https://www.edureka.co/blog/category/operating-systems/ "Operating Systems Blogs")[Operations Management](https://www.edureka.co/blog/category/operations-management/ "Operations Management Blogs")[Product Management](https://www.edureka.co/blog/category/product-management/ "Product Management Blogs")[Programming & Frameworks](https://www.edureka.co/blog/category/programming-and-frameworks/ "Programming & Frameworks Blogs")[Project Management and Methodologies](https://www.edureka.co/blog/category/project-management/ "Project Management and Methodologies Blogs")[Robotic Process Automation](https://www.edureka.co/blog/category/robotic-process-automation/ "Robotic Process Automation Blogs")[seo interview question](https://www.edureka.co/blog/category/seo-interview-question/ "seo interview question Blogs")[Software Testing](https://www.edureka.co/blog/category/software-testing/ "Software Testing Blogs")[Strategy and Leadership](https://www.edureka.co/blog/category/strategy-leadership/ "Strategy and Leadership Blogs")[Supply Chain Management](https://www.edureka.co/blog/category/supply-chain-managements/ "Supply Chain Management Blogs")[Systems & Architecture](https://www.edureka.co/blog/category/systems-architecture/ "Systems & Architecture Blogs") ![webinar](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2022%2022'%3E%3C/svg%3E) ![webinar](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/blog-001.svg) REGISTER FOR FREE WEBINAR ![webinar\_success](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E) ![webinar\_success](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/blog-tick.svg) Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month [JOIN MEETUP GROUP](https://www.meetup.com/edureka/) ### Subscribe to our Newsletter, and get personalized recommendations. ![Google](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2028%2016'%3E%3C/svg%3E) ![Google](https://d1jnx9ba8s6j9r.cloudfront.net/blog/assets/ver.2602261635/img/google-icon.svg) Sign up with Google ![facebook](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2028%2016'%3E%3C/svg%3E) ![facebook](https://d1jnx9ba8s6j9r.cloudfront.net/blog/assets/ver.2602261635/img/facebook-icon.svg) Signup with Facebook Already have an account? [**Sign in**](https://www.edureka.co/blog/python-metaclasses/). × ![](data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==) × #### 20,00,000 learners love us! Get personalised resources in your inbox. Sign up with Gmail Sign up with Facebook OR × ![imag]() Reshape Your Career\! #### Awesome We have recieved your contact details. You will recieve an email from us shortly. × ![image]() Main heading sub heading Click to avail You are here: 1. [Home](https://www.edureka.co/) 2. [Blog](https://www.edureka.co/blog/) 3. [Data Science](https://www.edureka.co/blog/category/data-science/) 4. [How To Create Your First Pytho...](https://www.edureka.co/blog/python-metaclasses/) [![edureka logo](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20150%2033'%3E%3C/svg%3E)![edureka logo](https://d1jnx9ba8s6j9r.cloudfront.net/img/Edureka_SNVA_New1_Ver_Logo.webp)](https://www.edureka.co/) #### TRENDING CERTIFICATION COURSES - [Advanced DevOps Certification Training with GenAI](https://www.edureka.co/devops-certification-training) - [Agentic AI Certification Training Course](https://www.edureka.co/agentic-ai-training-course) - [LLM Prompt Engineering Certification Course](https://www.edureka.co/prompt-engineering-with-llms-training-course) - [Data Science with Python Certification Course](https://www.edureka.co/data-science-python-certification-course) - [Power BI Certification Training with Gen AI](https://www.edureka.co/power-bi-certification-training) - [MLOps Certification Course](https://www.edureka.co/mlops-certification-training-course) - [Artificial Intelligence Certification Course](https://www.edureka.co/advanced-artificial-intelligence-course-python) #### TRENDING MASTERS COURSES - [Generative AI(Gen AI ) Masters Program](https://www.edureka.co/masters-program/generative-ai-prompt-engineering-training) - [Post Graduate Program in Gen AI and ML](https://www.edureka.co/executive-programs/pgp-generative-ai-machine-learning-certification-training) - [Doctor of Business Administration by Birchwood](https://www.edureka.co/online-doctorate-programs/doctor-of-business-administration-dba-birchwood) - [Integrated MS+PGP Program in Data Science & AI](https://www.edureka.co/dual-certification-programs/ms-data-science-pgp-gen-ai-ml-birchwood) - [MS in Data Science by Birchwood](https://www.edureka.co/online-doctorate-programs/ms-data-science-birchwood) - [European Global Doctorate of Business Administration (DBA)](https://www.edureka.co/online-doctorate-programs/doctor-of-business-administration-dba-european-global) - [European Global MS in Data Science and AI](https://www.edureka.co/online-doctorate-programs/ms-data-science-ai-european-global) - [EIMT Doctorate in Computer Science (DCS)](https://www.edureka.co/online-doctorate-programs/doctorate-of-computer-science-dcs-eimt) #### COMPANY - [About us](https://www.edureka.co/about-us) - [News & Media](https://www.edureka.co/allmedia) - [Reviews](https://www.edureka.co/reviews) - [Contact us](https://www.edureka.co/contact-us) - [Blog](https://www.edureka.co/blog/) - [Community](https://www.edureka.co/community/) - [Sitemap](https://www.edureka.co/sitemap) - [Blog Sitemap](https://www.edureka.co/blog/sitemap/) - [Community Sitemap](https://www.edureka.co/community/sitemap) - [Webinars](https://www.edureka.co/webinars) #### WORK WITH US - [Careers](https://www.edureka.co/careers) - [Become an Instructor](https://www.edureka.co/instructors/add) - [Become an Affiliate](https://www.edureka.co/affiliate-program) - [Become a Partner](https://www.edureka.co/partners) - [Hire from Edureka](https://www.edureka.co/hire-from-edureka) #### DOWNLOAD APP [![apple\_store](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20222%2066'%3E%3C/svg%3E)![apple\_store](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/applestore_img.png)](https://itunes.apple.com/in/app/edureka/id1033145415?mt=8) [![google\_playstore](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20222%2066'%3E%3C/svg%3E)![google\_playstore](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/playstore_img.png)](https://play.google.com/store/apps/details?id=co.edureka.app) ##### CATEGORIES #### CATEGORIES - [Cloud Computing](https://www.edureka.co/cloud-computing-certification-courses) - [DevOps](https://www.edureka.co/devops-certification-courses) - [Big Data](https://www.edureka.co/big-data-and-analytics) - [Data Science](https://www.edureka.co/data-science-certification-courses) - [BI and Visualization](https://www.edureka.co/bi-and-visualization-certification-courses) - [Programming & Frameworks](https://www.edureka.co/programming-and-frameworks-certification-courses) - [Software Testing](https://www.edureka.co/software-testing-certification-courses) - [Project Management and Methodologies](https://www.edureka.co/project-management-and-methodologies-certification-courses) - [Robotic Process Automation](https://www.edureka.co/robotic-process-automation-certification-courses) - [Frontend Development](https://www.edureka.co/frontend-development-certification-courses) - [Data Warehousing and ETL](https://www.edureka.co/data-warehousing-and-etl-certification-courses) - [Artificial Intelligence](https://www.edureka.co/artificial-intelligence-certification-courses) - [Blockchain](https://www.edureka.co/blockchain-certification-courses) - [Databases](https://www.edureka.co/databases-certification-courses) - [Cyber Security](https://www.edureka.co/cyber-security-certification-courses) - [Mobile Development](https://www.edureka.co/mobile-development-certification-courses) - [Operating Systems](https://www.edureka.co/operating-systems-certification-courses) - [Architecture & Design Patterns](https://www.edureka.co/architecture-and-design-patterns-certification-courses) - [Digital Marketing](https://www.edureka.co/digital-marketing-certification-courses) ##### TRENDING BLOG ARTICLES #### TRENDING BLOG ARTICLES - [Selenium tutorial](https://www.edureka.co/blog/selenium-tutorial) - [Selenium interview questions](https://www.edureka.co/blog/interview-questions/selenium-interview-questions-answers/) - [Java tutorial](https://www.edureka.co/blog/java-tutorial/) - [What is HTML](https://www.edureka.co/blog/what-is-html/) - [Java interview questions](https://www.edureka.co/blog/interview-questions/java-interview-questions/) - [PHP tutorial](https://www.edureka.co/blog/php-tutorial-for-beginners/) - [JavaScript interview questions](https://www.edureka.co/blog/interview-questions/javascript-interview-questions/) - [Spring tutorial](https://www.edureka.co/blog/spring-tutorial/) - [PHP interview questions](https://www.edureka.co/blog/interview-questions/php-interview-questions/) - [Inheritance in Java](https://www.edureka.co/blog/inheritance-in-java/) - [Polymorphism in Java](https://www.edureka.co/blog/polymorphism-in-java/) - [Spring interview questions](https://www.edureka.co/blog/interview-questions/spring-interview-questions/) - [Pointers in C](https://www.edureka.co/blog/pointers-in-c/) - [Linux commands](https://www.edureka.co/blog/linux-commands/) - [Android tutorial](https://www.edureka.co/blog/android-tutorial/) - [JavaScript tutorial](https://www.edureka.co/blog/javascript-tutorial/) - [jQuery tutorial](https://www.edureka.co/blog/jquery-tutorial/) - [SQL interview questions](https://www.edureka.co/blog/interview-questions/sql-interview-questions) - [MySQL tutorial](https://www.edureka.co/blog/mysql-tutorial/) - [Machine learning tutorial](https://www.edureka.co/blog/machine-learning-tutorial/) - [Python tutorial](https://www.edureka.co/blog/python-tutorial/) - [What is machine learning](https://www.edureka.co/blog/what-is-machine-learning/) - [Ethical hacking tutorial](https://www.edureka.co/blog/ethical-hacking-tutorial/) - [SQL injection](https://www.edureka.co/blog/sql-injection-attack) - [AWS certification career opportunities](https://www.edureka.co/blog/aws-certification-career-opportunities-in-amazon-web-services) - [AWS tutorial](https://www.edureka.co/blog/amazon-aws-tutorial/) - [What Is cloud computing](https://www.edureka.co/blog/what-is-cloud-computing/) - [What is blockchain](https://www.edureka.co/blog/what-is-blockchain/) - [Hadoop tutorial](https://www.edureka.co/blog/hadoop-tutorial/) - [What is artificial intelligence](https://www.edureka.co/blog/what-is-artificial-intelligence) - [Node Tutorial](https://www.edureka.co/blog/nodejs-tutorial/) - [Collections in Java](https://www.edureka.co/blog/java-collections/) - [Exception handling in java](https://www.edureka.co/blog/java-exception-handling) - [Python Programming Language](https://www.edureka.co/blog/python-programming-language) - [Python interview questions](https://www.edureka.co/blog/interview-questions/python-interview-questions/) - [Multithreading in Java](https://www.edureka.co/blog/java-thread/) - [ReactJS Tutorial](https://www.edureka.co/blog/reactjs-tutorial) - [Data Science vs Big Data vs Data Analytics](https://www.edureka.co/blog/data-science-vs-big-data-vs-data-analytics/) - [Software Testing Interview Questions](https://www.edureka.co/blog/interview-questions/software-testing-interview-questions/) - [R Tutorial](https://www.edureka.co/blog/r-tutorial/) - [Java Programs](https://www.edureka.co/blog/java-programs/) - [JavaScript Reserved Words and Keywords](https://www.edureka.co/blog/javascript-reserved-words/) - [Implement thread.yield() in Java: Examples](https://www.edureka.co/blog/thread-yield-in-java/) - [Implement Optical Character Recognition in Python](https://www.edureka.co/blog/optical-character-recognition-in-python/) - [All you Need to Know About Implements In Java](https://www.edureka.co/blog/implements-in-java/) Address: 4th Floor, No. 38/4, Outer Ring Rd, adjacent to Dell EMC2, Doddanekkundi, Mahadevapura, Bengaluru, Karnataka 560048 © 2026 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved. [Terms & Conditions](https://www.edureka.co/terms-and-conditions) [Legal & Privacy](https://www.edureka.co/privacy-policy) "PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc. ![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2014%2012'%3E%3C/svg%3E) ![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/multimedia-opt.png) ![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2040%2040'%3E%3C/svg%3E) ![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/cart-icon.svg) #### How To Create Your First Python Metaclass? edureka.co ![](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2010%2010'%3E%3C/svg%3E) ![](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/close.png) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2020%2020'%3E%3C/svg%3E) ![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/whatsapp.png) Whatsapp](https://api.whatsapp.com/send?phone&text=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F%20%20https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dwhatsapp%20%20%23Edureka&app_absent=0) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2020%2020'%3E%3C/svg%3E) ![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/linkedin.png) Linkedin](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dlinkedin&title=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F&summary=How%20To%20Create%20Your%20First%20Python%20Metaclass%3Fhttps%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dlinkedin%23Edureka&source=https%3A%2F%2Fwww.edureka.co%2Fblog) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2025%2020'%3E%3C/svg%3E) ![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/twitter.png) Twitter](https://twitter.com/intent/tweet?text=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F%20%20%23Edureka&url=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dtwitter&via=edurekain%20#Edureka) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2011%2020'%3E%3C/svg%3E) ![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/facebook.png) Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dfacebook&quote=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F%20%20https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dfacebook%20%20%23Edureka) [![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2023%2020'%3E%3C/svg%3E) ![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/reddit.png) Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fwww.edureka.co%2Fblog%2Fpython-metaclasses%3Futm_source%3Dsocialsharing%26utm_campaign%3Dreddit&title=How%20To%20Create%20Your%20First%20Python%20Metaclass%3F) Copy Link ![image not found\!](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2017%2017'%3E%3C/svg%3E) ![image not found\!](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/themes/edu-new/img/feather-link-black.png)
Readable Markdown
A Python Metaclass sets the behavior and rules of a class. Metaclass helps in modifying the instantiation of a class and is fairly complex and one of the advanced features of Python programming. Through this article, I will be discussing in-depth concepts of Python Metaclass, its properties, how and when to use a Metaclass in Python. This article covers the following concepts: 1. [What is Python Metaclass?](https://www.edureka.co/blog/python-metaclasses/#what-is-python-metaclass "What is Python Metaclass?") 2. [Classes and Objects in Python](https://www.edureka.co/blog/python-metaclasses/#classes-and-objects-in-python "Classes and Objects in Python") 3. [How Does Python Metaclass Work?](https://www.edureka.co/blog/python-metaclasses/#how-does-python-metaclass-work "How Does Python Metaclass Work?") Python Metaclass is one of the advanced features associated with [Object-Oriented Programming concepts](https://www.edureka.co/blog/object-oriented-programming-python/) of Python. It determines the behavior of a class and further helps in its modification. ![Metaclass hierarchy - Python Metaclass - Edureka](https://www.edureka.co/blog/wp-content/uploads/2020/07/final.png)Every class created in Python has an underlying Metaclass. So when you’re creating a class, you are indirectly using the Metaclass. It happens implicitly, you don’t need to specify anything. Metaclass when associated with metaprogramming determines the ability of a program to manipulate itself. Learning Metaclass might seem complex but let’s get a few concepts of [classes and objects](https://www.edureka.co/blog/python-class/) out of the way first, so that it’s simple to understand. ## **Classes and Objects in Python** A class is a blueprint, a logical entity having objects. A simple class when declared does not have any memory allocated, it happens when an instance of a class is created. Through the objects created, one can access the class. The class simply works as a template. The property of an object essentially means that we can interact with it at runtime, pass parameters like variables, store, modify, and can also interact with it. The class of an object can be checked by using the \_\_class\_\_ attribute. Let’s see this simple example: ``` class Demo: pass #This is a class named demo test=Demo() print(test.__class__) #shows class of obj print(type(test)) #alternate method ``` `Output: <class '__main__.Demo'>` Python heavily deals with the concept of classes and objects and allows easy and smooth application development. But what makes [Python](https://www.edureka.co/blog/learn-python/) different from languages like [Java](https://www.edureka.co/blog/java-tutorial/) and [C](https://www.edureka.co/blog/c-programming-tutorial/)? ***Everything in Python can be defined as an object having attributes and methods.*** Keynote is that classes in Python are nothing but another object of a bigger class. ~~![Instances of metaclass - Python metaclass - Edureka](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2020/07/final1.png)~~ A class defines rules for an object. Similarly, a Metaclass is responsible for assigning behaviors for the classes. We have learned that Class is an object, and like every object has an instance, a class is an instance of a Metaclass. But there are languages like [Ruby](https://www.edureka.co/blog/ruby-on-rails-tutorial/) and Objective-C which support Metaclasses as well. So, what makes Python Metaclass better and why should you learn it? The answer is the dynamic class in Python. Let’s take a closer look at it. ## **Dynamic Class in Python** Python is a dynamic programming language and allows the creation of a class at runtime. Unlike other languages like C++, which only allows the class creation at compile time. In terms of flexibility, Python has an advantage over other languages that are statically typed. The difference between dynamic and statically typed language isn’t much, but in Python, it becomes more useful because it provides metaprogramming. But what if I tell you that there’s another key feature that distinguishes Python from other programming languages? Languages like Java or [C++](https://www.edureka.co/blog/cpp-tutorial/) have data types like float, char, int, etc. whereas Python treats each variable as an object. And each object belongs to a class like an int class or str class. You can simply check the class of any variable using a built-in function called **type().** ``` number = 10993 print("Type associated is:", type(number)) name = "Aishwarya" print("Type associated is:", type(name)) ``` `Output: ` `Type associated is:  <class 'int'>` `Type associated is: <class 'str'>` Now that you understand everything in Python has a type associated with it. In the next topic, we will try to understand how Metaclass actually works. Whenever a class is created the default Metaclass which is type class gets called instead. Metaclass carries information like name, set of a base class, and attributes associated with the class. Hence, when a class is instantiated type class is called carrying these arguments. Metaclass can be created via two methods: 1. Type class 2. Custom Metaclass Let’s move on to type class and how you can create one. ### **Type Class** Python has a built-in Metaclass called type. Unlike Java or C, where there are primary data types. Every variable or object in Python has a class associated with it. Python use Type class behind-the-scenes to create all the classes. In the previous topic, we saw how we can check the class of an object by using **type().** Let’s take an example of how we can define a new type, by creating a simple class. ``` class Edureka(): obj = Edureka() print(type(obj)) ``` `Output: <class '__main__.Edureka'>` ``` print(type(Edureka)) ``` `Output: <class 'type'>` In the above code, we have a class called Edureka, and an object associated. We created a new type called Edureka by simply creating a class named itself after the type. In the second code, when we check the type of Edureka class, it results as ‘type’. So, unless defined otherwise, Metaclasses use **type class** to create all the other classes. We can access Type class via two methods: ![methods to use type class - Python metaclass - Edureka](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2020/07/type-class-1.png) When we pass parameters through type class, it uses the following syntax. ``` type(__name__, __base__, attributes) ``` where, - the name is a string and carries the class name - the base is a tuple and helps create subclasses - an attribute is a dictionary and assigns key-value pairs Since classes in Python behave similar to the objects, their behavior could be altered in the same way. We can add or remove methods within a class similar to how we do with objects. Now that you know Metaclass creates all the other classes in Python and defines their behavior using type class. But then you must be wondering, is there any other way we can create Metaclass? So, let’s see how to create a custom Metaclass that. Ready to unlock the power of data? Dive into [Python for Data Science](https://www.edureka.co/data-science-python-certification-course) today! Whether you’re analyzing trends, building predictive models, or extracting valuable insights, Python’s versatile libraries like NumPy, pandas, and scikit-learn empower you to conquer any data challenge ### **Custom Metaclass in Python** Now that we know and understand how the type class works. It’s time to learn how we can create our custom Metaclass. We can modify the working of classes by carrying actions or code injection. To achieve this, we can pass Metaclass as a keyword while creating a class definition. Alternatively, we can achieve this by simply inheriting a class that has been instantiated through this Metaclass keyword. At the time of creating a new class, Python looks for the **\_\_metaclass\_\_** keyword. In case, if it isn’t present. It follows the type class hierarchy. ![custom type class hierarchy - Python metaclass - Edureka](https://d1jnx9ba8s6j9r.cloudfront.net/blog/wp-content/uploads/2020/07/final2-300x296.png) After Python executes all the dictionary in a namespace, it invokes type object which creates objects of a class. There are two methods that we can use to create custom Metaclass. ``` custom metaclass methods - Python metaclass - Edureka ``` ``` class EduFirst(type): def __new__(cls, name, base_cls, dict): pass class EduSecond(type): def __init__(self, name, base_cls, dict): pass ``` Let me explain these two methods in detail: 1. **\_\_new\_\_():** is used when a user wants to define a dictionary of tuples before the class creation. It returns an instance of a class and is easy to override/manage the flow of objects. 2. **\_\_init\_\_()**: It’s called after the object has already been created and simply initializes it. ### **What is \_\_call\_\_ in Python?** In the official [Python documents](https://docs.python.org/3/tutorial/index.html), the **\_\_call\_\_** method can be used to define a custom Metaclass. Also, we can override other methods like \_\_prepare\_\_ when calling a class to define custom behavior. Much like how a class behaves like a template to create objects, in the same way, Metaclass acts like a template for the class creation. Therefore, a Metaclass is also known as a class factory. See the next example: ``` class Meta(type): def __init__(cls, name, base, dct): cls.attribute = 200 class Test(metaclass = Meta): pass Test.attribute ``` `Output: 200` Metaclass allows class customization. There are various other effective and much simpler ways through which the same output can be achieved. One such example is using Decorators. [Decorator](https://www.edureka.co/blog/python-decorator-tutorial/) is a popular feature of Python which allows you to add more functionality to the code. A decorator is a callable object which helps modify the existing class or even a function. During compilation, part of code calls and modifies another part. This process is also known as metaprogramming. | | | |---|---| | **Decorator** | **Metaclass** | | Returns the same class after making changes (e.g.: monkey-patching) | We use Metaclass whenever a new class is created | | Lacks flexibility | Provides flexibility and customization of classes | | Isn’t compatible to perform subclassing | Provides subclassing by using inheritance and converting object methods to static methods for better optimization | ``` def decorator(cls): class NewClass(cls): attribute = 200 return NewClass @decorator Class Test1: pass @decorator Class Test2: pass Test1.attribute Test2.attribute ``` `Output: 200` [Decorator in Python](https://www.edureka.co/blog/decorators-in-python/) is a very useful and powerful tool that helps change the behavior of a function without actually changing any of the code. This comes handy when you want to modify a part of the program while debugging, instead of rewriting the function or changing the entire program. Instead, you can simply write a single line decorator and it will take care of the rest. This brings us to the end of the session. Hopefully, this article helped you understand what is Metaclass and how and when to use it. *If you found this article on “Python Metaclass” relevant, check out [Edureka’s Python Programming Certification Course](https://www.edureka.co/python-programming-certification-training) a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.* *We are here to help you with every step on your journey and come up with a curriculum that is designed for students and professionals who want to be a [Python developer](https://www.edureka.co/blog/how-to-become-a-python-developer/). The course is designed to give you a head start into Python programming and train you for both core and advanced Python concepts along with various [Python frameworks](https://www.edureka.co/blog/python-frameworks/) like [Django.](https://www.edureka.co/blog/django-tutorial/)* *If you come across any questions, feel free to ask all your questions in the comments section of “Python Metaclass”. Our team will be glad to answer.*
Shard151 (laksa)
Root Hash3655379734502321551
Unparsed URLco,edureka!www,/blog/python-metaclasses/ s443