{"id":11679,"date":"2016-03-28T16:15:10","date_gmt":"2016-03-28T13:15:10","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=11679"},"modified":"2018-01-09T09:42:31","modified_gmt":"2018-01-09T07:42:31","slug":"python-class-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/","title":{"rendered":"Python Class Example"},"content":{"rendered":"<p>In this tutorial, we&#8217;ll talk about <em>classes<\/em>. By using Python 3.4, we will talk about what classes are, how do we use them and what can we do with them.<\/p>\n<p>Python is an object-oriented programming language, and as such it has a class mechanism. Classes are extensible templates for creating objects, providing initial values for state (variables) and implementation of behavior (functions and methods).<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;R7QVpFMZmjosABLC&#8217;]<br \/>\n&nbsp;<br \/>\nCompared with other languages, Python&#8217;s class mechanism adds classes with a minimum of new syntax. See:<\/p>\n<pre class=\"brush:python\">\r\nclass ClassName:\r\n    body\r\n<\/pre>\n<p>The only new thing we need to learn to create a class as simple as this one is the keyword <code>class<\/code>, pretty simple. To get an instance of this class, we don&#8217;t need to add a new keyword to our dictionary, we just do <code>my_var = ClassName()<\/code>, and now <code>my_var<\/code> is an instance of <code>ClassName<\/code>. Still simple.<\/p>\n<p>Let&#8217;s talk about the <em>body<\/em> of a class. When we define a class, its body is executed, in other words if we write a script that contains only the next piece of code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>simple.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nclass MyBodyWillBeExecuted:\r\n    print(\"MyBodyWillBeExecuted is being defined\")\r\n<\/pre>\n<p>By running it, like <code>python3 simple.py<\/code>, the output will say:<\/p>\n<pre class=\"brush:bash\">\r\n$ python3 simple.py\r\nMyBodyWillBeExecuted is being defined\r\n<\/pre>\n<p>And that is actually how class variables are defined, but before we see an example, let&#8217;s see a definition. Class variables are variables that are available at class level, all instances of a class will be able to access these variables. If you come from Java, you can think of them as static variables. Now, let&#8217;s see:<\/p>\n<p><span style=\"text-decoration: underline\"><em>simple.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nclass MyBodyWillBeExecuted:\r\n    class_variable = \"a value\"\r\n<\/pre>\n<p>Now <code>MyBodyWillBeExecuted<\/code> has a class variable, every instance of <code>MyBodyWillBeExecuted<\/code> will be able to read <code>class_variable<\/code>. Now, as in every other OOP language that I know of, classes in Python have constructors.<\/p>\n<p>A constructor in Python is a function that is executed when an instance of its class is created, and is always called <code>__init__<\/code>, let&#8217;s see:<\/p>\n<p><span style=\"text-decoration: underline\"><em>simple.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nclass MyBodyWillBeExecuted:\r\n    print(\"this print is executed when the class is defined\")\r\n    class_variable = \"a value\"\r\n\r\n    def __init__(self):\r\n        print(\"this print is executed when an instance of this class is created\")\r\n\r\na = MyBodyWillBeExecuted()\r\nb = MyBodyWillBeExecuted()\r\n<\/pre>\n<p>That <code>__init__(self)<\/code> is the constructor of our class. This function receives a parameter, <code>self<\/code>, we&#8217;ll talk about this later. Now, let&#8217;s see the output of this script:<\/p>\n<pre class=\"brush:bash\">\r\n$ python3 simple.py\r\nthis print is executed when the class is defined\r\nthis print is executed when an instance of this class is created\r\nthis print is executed when an instance of this class is created\r\n<\/pre>\n<p>As you see, the <em>&#8220;this print is executed when the class is defined&#8221;<\/em> message is printed once when we defined the class, and the <em>&#8220;this print is executed when an instance of this class is created&#8221;<\/em> message is printed twice, once for every instance of <code>MyBodyWillBeExecuted<\/code> we create.<\/p>\n<p>Let&#8217;s talk about that <code>self<\/code> argument. In Python, there are no shorthands for referencing the object\u2019s members from its methods\/functions, the method\/function is defined with an explicit first argument representing the object, which is provided implicitly by the call. This is not specific to the <code>__init__<\/code> method, but for all instance methods. This might seem a little weird, but you&#8217;ll get the hang of it by practice.<\/p>\n<p>Now that we&#8217;ve cleared out that <code>self<\/code> argument, we can talk about instance variables. To create a variable in an instance of a class, you need to assign its value to a property of <code>self<\/code>. Let&#8217;s see:<\/p>\n<p><span style=\"text-decoration: underline\"><em>simple.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nclass MyBodyWillBeExecuted:\r\n    class_variable = \"a value\"\r\n\r\n    def __init__(self, n):\r\n        self.n = n\r\n\r\na = MyBodyWillBeExecuted(1)\r\nb = MyBodyWillBeExecuted(2)\r\n\r\nprint(a.n)\r\nprint(b.n)\r\n<\/pre>\n<p>The new script changed the constructor signature, as it now receives an argument <code>n<\/code> and assigns it to <code>self.n<\/code>. That <code>self.n<\/code> will be available in every instance of that class, as we see in the print statements that are printing <code>a.n<\/code> and <code>b.n<\/code>. The output below.<\/p>\n<pre class=\"brush:bash\">\r\n$ python3 simple.py\r\n1\r\n2\r\n<\/pre>\n<p>Now, let&#8217;s access that variable from another method, called <code>add_one<\/code>:<\/p>\n<p><span style=\"text-decoration: underline\"><em>simple.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nclass MyBodyWillBeExecuted:\r\n    class_variable = \"a value\"\r\n\r\n    def __init__(self, n):\r\n        self.n = n\r\n\r\n    def add_one(self):\r\n        self.n += 1\r\n        return self.n\r\n\r\na = MyBodyWillBeExecuted(1)\r\nb = MyBodyWillBeExecuted(2)\r\n\r\nwhile a.n &lt; 10:\r\n    a.add_one()\r\n\r\nprint(a.n)\r\nprint(b.n)\r\n<\/pre>\n<p>From another function now, we are accessing the instance variable <code>n<\/code>, by doing <code>self.n<\/code>. Let&#8217;s see the output.<\/p>\n<pre class=\"brush:bash\">\r\n$ python3 simple.py\r\n10\r\n2\r\n<\/pre>\n<p>One thing that&#8217;s worth noticing here, is that we have made all variables and functions public until now&#8230; well, that&#8217;s actually not optional, Python doesn&#8217;t provide a way of making things private. Instead, there is a convention, every name prefixed with an underscore should be treated as a non-public part of the class.<\/p>\n<p>Let&#8217;s see an example of this:<\/p>\n<p><span style=\"text-decoration: underline\"><em>simple.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nclass MyBodyWillBeExecuted:\r\n    class_variable = \"a value\"\r\n\r\n    def __init__(self, n):\r\n        self.n = n\r\n\r\n    def _add(self, n):\r\n        self.n += n\r\n\r\n    def add_one(self):\r\n        self._add(1)\r\n        return self.n\r\n\r\na = MyBodyWillBeExecuted(1)\r\nb = MyBodyWillBeExecuted(2)\r\n\r\nwhile a.n &lt; 10:\r\n    a.add_one()\r\n\r\nb._add(1)\r\n\r\nprint(a.n)\r\nprint(b.n)\r\n<\/pre>\n<p>We defined a new method called <code>_add<\/code> that receives a number as argument and adds it to <code>self.n<\/code>. This method will be available outside of the instance, as you can see when we do <code>b._add(1)<\/code>, but you shouldn&#8217;t call this method from outside, it&#8217;s a convention that almost every Python programmer knows and follows.<\/p>\n<p>Also, Python provides a mechanism to hide things to prevent them from being accessed from outside a class, but let&#8217;s make it clear, it is not making anything private. If you name a member of a class with two underscores as prefix, Python will internally change its name to include the class name, this means that if you have an attribute called <code>__private_member<\/code> in a class called <code>AClass<\/code>, Python will internally rename this attribute <code>_AClass__private_member<\/code> and refactor every internal calls, but not external ones. Of course, you can still access this member by doing <code>instance._AClass__private_member<\/code>, so it is not actually private. I don&#8217;t really do this often, but maybe I should, I just really don&#8217;t see the point.<\/p>\n<p>Let&#8217;s do some recap. We&#8217;ve talked about classes syntax, constructors, class variables and instance variables and instance methods\/functions, let&#8217;s talk about <em>destructors<\/em>.<\/p>\n<p>As you might know, Python deletes unreferenced objects automatically to free memory space (garbage collection). This process runs during program execution and it&#8217;s triggered when an object&#8217;s reference count reaches zero. An object&#8217;s reference count increases when it is assigned a new name or placed in a container (list, tuple, or dictionary). The object&#8217;s reference count decreases when it&#8217;s deleted with del, its reference is reassigned, or its reference goes out of scope. When an object&#8217;s reference count reaches zero, Python collects it automatically.<\/p>\n<p>In most cases (integers, strings, list, dictionaries, etc.), you won&#8217;t notice when an object is deleted, but a class can implement the <code>__del__<\/code> method, which will be invoked right before the instance is destroyed. This method was meant to be used to release non memory resources an instance may use (files, sockets, etc.). Let&#8217;s see:<\/p>\n<p><span style=\"text-decoration: underline\"><em>simple.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nclass MyBodyWillBeExecuted:\r\n    class_variable = \"a value\"\r\n\r\n    def __init__(self, n):\r\n        self.n = n\r\n\r\n    def _add(self, n):\r\n        self.n += n\r\n\r\n    def add_one(self):\r\n        self._add(1)\r\n        return self.n\r\n\r\n    def __del__(self):\r\n        print(\"I'm being destroyed... Goodbye world!\")\r\n\r\na = MyBodyWillBeExecuted(1)\r\nb = MyBodyWillBeExecuted(2)\r\n\r\nwhile a.n &lt; 10:\r\n    a.add_one()\r\n\r\nb._add(1)\r\n\r\nprint(a.n)\r\n\r\na = None\r\n\r\nprint(b.n)\r\n<\/pre>\n<p>Every instance of this class will print <em>&#8220;I&#8217;m being destroyed&#8230; Goodbye world!&#8221;<\/em> when Python is about to destroy it and reclaim the memory consumed by it. So, let&#8217;s predict what is going to happen:<\/p>\n<ul>\n<li>The class <code>MyBodyWillBeExecuted<\/code> is defined and two instances of it are created (a and b).<\/li>\n<li>The method <code>a.add_one()<\/code> is called until <code>a.n<\/code> is 10 and <code>b._add(1)<\/code> is executed.<\/li>\n<li>The value of <code>a.n<\/code> is printed, and then <code>None<\/code> is assigned to a. Now the instance of <code>MyBodyWillBeExecuted<\/code> that was referenced by a is an orphan, no one is pointing to it, so it will be destroyed.<\/li>\n<li>The value of <code>b.n<\/code> is printed.<\/li>\n<li>The program, about to be terminated, will destroy the remaining instance of <code>MyBodyWillBeExecuted<\/code>.<\/li>\n<\/ul>\n<p>Let&#8217;s see the output to check this program behaves as expected:<\/p>\n<pre class=\"brush:bash\">\r\n$ python3 simple.py\r\n10\r\nI'm being destroyed... Goodbye world!\r\n3\r\nI'm being destroyed... Goodbye world!\r\n<\/pre>\n<p>Now, let&#8217;s see a complete example of what we&#8217;ve seen here. We&#8217;ll write a class <code>User<\/code>, which will contain a <code>name<\/code> and a <code>password<\/code>, we&#8217;ll see what to do with it later.<\/p>\n<p><span style=\"text-decoration: underline\"><em>basic.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\n...\r\nclass User:\r\n\r\n    def __init__(self, name, password):\r\n        self.name = name\r\n        self.password = password\r\n...\r\n<\/pre>\n<p>It&#8217;s a simple class, with two instance variables, nothing too hard. Now, passwords are supposed to be stored hashed, so, let&#8217;s do that. Let&#8217;s write a class called <code>Hasher<\/code>, that will hold an instance variable <code>salt<\/code> and a function <code>hash<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>basic.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\n...\r\nimport hashlib, binascii\r\n...\r\nclass Hasher:\r\n\r\n    def __init__(self, salt):\r\n        self._salt = salt\r\n\r\n    def hash(self, value):\r\n        bin_hash = hashlib.pbkdf2_hmac('sha512', value.encode('utf-8'), self._salt, 100000)\r\n        return binascii.hexlify(bin_hash).decode('utf-8')\r\n...\r\n<\/pre>\n<p>The constructor receives a variable called <code>salt<\/code> and stores it in an instance variable. The function <code>hash<\/code> receives a value, uses <code>pbkdf2<\/code> from <code>hashlib<\/code> (a module provided by Python) to hash it, and then the module <code>binascii<\/code> to translate the returned binary into a hex string. The resulting string is returned.<\/p>\n<p>Now we need a place to store this users, let&#8217;s call it <code>UserStorage<\/code>. It will store users in a dictionary, indexed by the user&#8217;s name, to guarantee that it will be unique.<\/p>\n<p><span style=\"text-decoration: underline\"><em>basic.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\n...\r\nclass UserStorage:\r\n\r\n    def __init__(self):\r\n        self._store = {}\r\n\r\n    def store(self, user):\r\n        self._store[user.name] = user\r\n\r\n    def find(self, user_name):\r\n        return self._store.get(user_name)\r\n...\r\n<\/pre>\n<p>It isn&#8217;t doing anything strange, there is a constructor that initializes an instance variable <code>_store<\/code> as an empty dictionary, then there are two functions, one to store an user and another one to retrieve a user by its name. Let&#8217;s glue it all together in a GUI (Graphic User Interface).<\/p>\n<p>We&#8217;ll write a class <code>GUI<\/code> that will print and prompt stuff from the console.<\/p>\n<p><span style=\"text-decoration: underline\"><em>basic.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\n...\r\nimport getpass\r\n...\r\nclass GUI:\r\n\r\n    def __init__(self, storage, hasher):\r\n        self._storage = storage\r\n        self._hasher = hasher\r\n\r\n    def _create_user(self):\r\n        user_name = input(\"user name: \")\r\n        password = self._hasher.hash(getpass.getpass(prompt=\"password: \"))\r\n        user = User(user_name, password)\r\n        self._storage.store(user)\r\n\r\n    def _check_login(self):\r\n        user_name = input(\"user name: \")\r\n        password = self._hasher.hash(getpass.getpass(prompt=\"password: \"))\r\n        user = self._storage.find(user_name)\r\n        if user is None or user.password != password:\r\n            print(\"login failed\")\r\n        else:\r\n            print(\"login successful\")\r\n\r\n    def main_menu(self):\r\n        print(\"1. Create User\\n2. Check Login\\n0. Exit\")\r\n        option = int(input(\"what do you want to do? \"))\r\n        if option == 1:\r\n            self._create_user()\r\n        elif option == 2:\r\n            self._check_login()\r\n        if option != 0:\r\n            self.main_menu()\r\n...\r\n<\/pre>\n<p>This class has a constructor that receives a <code>Hasher<\/code> and a <code>UserStorage<\/code>, and holds them in instance variables. There is one <em>&#8220;public&#8221;<\/em> function called <code>main_menu<\/code> that will print the options and take action according user&#8217;s input, it&#8217;s a recursive function that will keep calling itself until the user inputs 0.<\/p>\n<p>If the user inputs 1, <code>main_menu<\/code> will call <code>self._create_user<\/code>, a <em>&#8220;private&#8221;<\/em> method that will ask the user for the user name and password, hash the password, create the <code>User<\/code> and store it.<\/p>\n<p>If the user inputs 2, <code>main_menu<\/code> will call <code>self._check_login<\/code>, another <em>&#8220;private&#8221;<\/em> method that will ask the user for credentials and check them with the <code>UserStorage<\/code>.<\/p>\n<p>To ask for passwords, this class uses a module called <code>getpass<\/code> provided by Python, which is a tool to ask for passwords from the terminal, passwords written in the terminal when prompted with <code>getpass<\/code> will not be shown. Let&#8217;s see how the whole code looks like.<\/p>\n<pre class=\"brush:python\">\r\nimport hashlib, binascii, getpass\r\n\r\n\r\nclass Hasher:\r\n\r\n    def __init__(self, salt):\r\n        self._salt = salt\r\n\r\n    def hash(self, value):\r\n        bin_hash = hashlib.pbkdf2_hmac('sha512', value.encode('utf-8'), self._salt, 100000)\r\n        return binascii.hexlify(bin_hash).decode('utf-8')\r\n\r\n\r\nclass User:\r\n\r\n    def __init__(self, name, password):\r\n        self.name = name\r\n        self.password = password\r\n\r\n\r\nclass UserStorage:\r\n\r\n    def __init__(self):\r\n        self._store = {}\r\n\r\n    def store(self, user):\r\n        self._store[user.name] = user\r\n\r\n    def find(self, user_name):\r\n        return self._store.get(user_name)\r\n\r\n\r\nclass GUI:\r\n\r\n    def __init__(self, storage, hasher):\r\n        self._storage = storage\r\n        self._hasher = hasher\r\n\r\n    def _create_user(self):\r\n        user_name = input(\"user name: \")\r\n        password = self._hasher.hash(getpass.getpass(prompt=\"password: \"))\r\n        user = User(user_name, password)\r\n        self._storage.store(user)\r\n\r\n    def _check_login(self):\r\n        user_name = input(\"user name: \")\r\n        password = self._hasher.hash(getpass.getpass(prompt=\"password: \"))\r\n        user = self._storage.find(user_name)\r\n        if user is None or user.password != password:\r\n            print(\"login failed\")\r\n        else:\r\n            print(\"login successful\")\r\n\r\n    def main_menu(self):\r\n        print(\"1. Create User\\n2. Check Login\\n0. Exit\")\r\n        option = int(input(\"what do you want to do? \"))\r\n        if option == 1:\r\n            self._create_user()\r\n        elif option == 2:\r\n            self._check_login()\r\n        if option != 0:\r\n            self.main_menu()\r\n\r\nif __name__ == '__main__':\r\n    user_storage = UserStorage()\r\n    hasher = Hasher(b\"some_salt\")\r\n    GUI(user_storage, hasher).main_menu()\r\n<\/pre>\n<p>The main code initialized both the <code>UserStorage<\/code> and the <code>Hasher<\/code> and then creates the <code>GUI<\/code> and starts the <code>main_menu<\/code>. Let&#8217;s see the output.<\/p>\n<pre class=\"brush:bash\">\r\n$ python3 basic.py\r\n1. Create User\r\n2. Check Login\r\n0. Exit\r\nwhat do you want to do? 1\r\nuser name: svinci\r\npassword:\r\n1. Create User\r\n2. Check Login\r\n0. Exit\r\nwhat do you want to do? 2\r\nuser name: svinci\r\npassword:\r\nlogin successful\r\n1. Create User\r\n2. Check Login\r\n0. Exit\r\nwhat do you want to do? 2\r\nuser name: svinci\r\npassword:\r\nlogin failed\r\n1. Create User\r\n2. Check Login\r\n0. Exit\r\nwhat do you want to do? 2\r\nuser name: asd\r\npassword:\r\nlogin failed\r\n1. Create User\r\n2. Check Login\r\n0. Exit\r\nwhat do you want to do? 0\r\n<\/pre>\n<p>This input shows how to create a user, and then tests a successful login, a login with the wrong password and another one with the wrong user name. Let&#8217;s jump to the next subject now, which is inheritance.<\/p>\n<p>In Python, as in most OOP languages, you can write classes that inherit from other classes. If you have a class <code>Car<\/code> and another class <code>Bus<\/code>, you&#8217;ll find that they have a lot in common, and that&#8217;s because they are both vehicles, so it would be a good idea to make them inherit from a class <code>Vehicle<\/code>. Let&#8217;s see it in practice.<\/p>\n<p>We&#8217;ll write a class <code>Vehicle<\/code> that holds the information every vehicle has, no matter if it&#8217;s a bus, a car or a motorcycle. Then, this class will define the behavior every vehicle has: <code>accelerator<\/code>, <code>breaks<\/code>, <code>honk<\/code> and <code>speedometer<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>inheritance.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nclass Vehicle:\r\n\r\n    def __init__(self, wheels, max_speed, acceleration, breaks_acceleration, brand, model):\r\n        self.wheels = wheels\r\n        self.max_speed = max_speed\r\n        self.acceleration = acceleration\r\n        self.breaks_acceleration = breaks_acceleration\r\n        self.current_speed = 0\r\n        self.brand = brand\r\n        self.model = model\r\n\r\n    def accelerator(self, target_speed):\r\n        while self.current_speed &lt; target_speed and self.current_speed &lt; self.max_speed:\r\n            self.current_speed += self.acceleration\r\n        self.speedometer()\r\n\r\n    def breaks(self, target_speed=0):\r\n        while self.current_speed &gt; 0 and self.current_speed &gt; target_speed:\r\n            self.current_speed -= self.breaks_acceleration\r\n        self.speedometer()\r\n\r\n    def speedometer(self):\r\n        print(\"{}, {}: {} kmph\".format(self.brand, self.model, self.current_speed))\r\n\r\n    def honk(self):\r\n        print(\"HONK!\")\r\n...\r\n<\/pre>\n<p>It&#8217;s pretty basic, but it will do the job. As you see, this class is written as any other class we&#8217;ve wrote so far, not additional syntax is necessary to be able to inherit from a class. As I&#8217;m from Argentina, the speed will be measured in kilometers per hour (kmph). Now, let&#8217;s see, having this class, how we can write <code>Car<\/code> and <code>Bus<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>inheritance.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\n...\r\nclass Car(Vehicle):\r\n    def __init__(self):\r\n        Vehicle.__init__(self, 4, 130, 10, 30, \"Ford\", \"Focus\")\r\n\r\n\r\nclass Bus(Vehicle):\r\n    def __init__(self):\r\n        Vehicle.__init__(self, 4, 80, 5, 50, \"Mercedes\", \"Don't Know any model of bus\")\r\n...\r\n<\/pre>\n<p>Those are some really tiny classes there, but they are powerful enough for us, as they hold all the variables and behavior as a <code>Vehicle<\/code>.<\/p>\n<p>As you might see, to inherit from a class we write its name between parentheses between the name of our class and the colon. Then, in the constructor, we need to call our parent class&#8217; constructor giving <code>self<\/code> as first argument. Let&#8217;s see it all together now.<\/p>\n<p><span style=\"text-decoration: underline\"><em>inheritance.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nclass Vehicle:\r\n\r\n    def __init__(self, wheels, max_speed, acceleration, breaks_acceleration, brand, model):\r\n        self.wheels = wheels\r\n        self.max_speed = max_speed\r\n        self.acceleration = acceleration\r\n        self.breaks_acceleration = breaks_acceleration\r\n        self.current_speed = 0\r\n        self.brand = brand\r\n        self.model = model\r\n\r\n    def accelerator(self, target_speed):\r\n        while self.current_speed &lt; target_speed and self.current_speed &lt; self.max_speed:\r\n            self.current_speed += self.acceleration\r\n        self.speedometer()\r\n\r\n    def breaks(self, target_speed=0):\r\n        while self.current_speed &gt; 0 and self.current_speed &gt; target_speed:\r\n            self.current_speed -= self.breaks_acceleration\r\n        self.speedometer()\r\n\r\n    def speedometer(self):\r\n        print(\"{}, {}: {} kmph\".format(self.brand, self.model, self.current_speed))\r\n\r\n    def honk(self):\r\n        print(\"HONK!\")\r\n\r\n\r\nclass Car(Vehicle):\r\n\r\n    def __init__(self):\r\n        Vehicle.__init__(self, 4, 130, 10, 30, \"Ford\", \"Focus\")\r\n\r\n\r\nclass Bus(Vehicle):\r\n    def __init__(self):\r\n        Vehicle.__init__(self, 4, 80, 5, 50, \"Mercedes\", \"Don't Know any model of bus\")\r\n\r\nif __name__ == '__main__':\r\n    bus = Bus()\r\n    car = Car()\r\n    car.accelerator(40)\r\n    bus.accelerator(40)\r\n    car.breaks(20)\r\n    bus.honk()\r\n    car.accelerator(40)\r\n<\/pre>\n<p>In the main code, we instantiate a <code>Bus<\/code> and a <code>Car<\/code>, the car then goes at 40 kmph, the bus follows along, the car breaks, the bus honks so the car accelerates again. Let&#8217;s see the output.<\/p>\n<pre class=\"brush:bash\">\r\n$ python3 inheritance.py\r\nFord, Focus: 40 kmph\r\nMercedes, Don't Know any model of bus: 40 kmph\r\nFord, Focus: 10 kmph\r\nHONK!\r\nFord, Focus: 40 kmph\r\n<\/pre>\n<p>Great. We&#8217;ve got these vehicles working, but wait, what if our bus have some super futuristic breaks that actually have no acceleration, but changes the speed to 0 instantly? Everyone on the bus would probably die, but still, let&#8217;s do it. Let&#8217;s override the <code>breaks<\/code>.<\/p>\n<p>You can always override your parent class methods. One reason for overriding parent&#8217;s methods is because you may want special or different functionality in your subclass. In Python no keywords or special syntax is needed, we just re define the method we want to override, see.<\/p>\n<p><span style=\"text-decoration: underline\"><em>inheritance.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\n...\r\nclass Bus(Vehicle):\r\n    def __init__(self):\r\n        Vehicle.__init__(self, 4, 80, 5, 50, \"Mercedes\", \"Don't Know any model of bus\")\r\n\r\n    def breaks(self, target_speed=0):\r\n        print(\"SUPER AWESOME BREAKS!\")\r\n        self.current_speed = target_speed\r\n        self.speedometer()\r\n...\r\n<\/pre>\n<p>This bus will break a lot faster than any other vehicle. Let&#8217;s use these new breaks by changing our main code.<\/p>\n<p><span style=\"text-decoration: underline\"><em>inheritance.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\n...\r\nif __name__ == '__main__':\r\n    bus = Bus()\r\n    car = Car()\r\n    car.accelerator(40)\r\n    bus.accelerator(40)\r\n    car.breaks(20)\r\n    bus.honk()\r\n    car.accelerator(40)\r\n    bus.breaks(0)\r\n...\r\n<\/pre>\n<p>The new output can be found below.<\/p>\n<pre class=\"brush:bash\">\r\n$ python3 inheritance.py\r\nFord, Focus: 40 kmph\r\nMercedes, Don't Know any model of bus: 40 kmph\r\nFord, Focus: 10 kmph\r\nHONK!\r\nFord, Focus: 40 kmph\r\nSUPER AWESOME BREAKS!\r\nMercedes, Don't Know any model of bus: 0 kmph\r\n<\/pre>\n<p>The behavior remains the same for all methods, except for the breaks of the bus. Now, our car&#8217;s accelerator is broken, it adds 10 kmph to the target speed when it&#8217;s accelerated. Let&#8217;s write that.<\/p>\n<p><span style=\"text-decoration: underline\"><em>inheritance.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\n...\r\nclass Car(Vehicle):\r\n    def __init__(self):\r\n        Vehicle.__init__(self, 4, 130, 10, 30, \"Ford\", \"Focus\")\r\n\r\n    def accelerator(self, target_speed=0):\r\n        super().accelerator(target_speed + 10)\r\n...\r\n<\/pre>\n<p>To call our parent class&#8217; method <code>accelerator<\/code> within our child class, we use the built-in function <code>super()<\/code>. Let&#8217;s see the behavior of this.<\/p>\n<pre class=\"brush:bash\">\r\n$ python3 inheritance.py\r\nFord, Focus: 50 kmph\r\nMercedes, Don't Know any model of bus: 40 kmph\r\nFord, Focus: 20 kmph\r\nHONK!\r\nFord, Focus: 50 kmph\r\nSUPER AWESOME BREAKS!\r\nMercedes, Don't Know any model of bus: 0 kmph\r\n<\/pre>\n<p>Now our car is 50 kmph instead of 40 kmph, just as we&#8230; wanted? Well, it is what it is, we need to take it to the mechanic.<\/p>\n<h2>3. Download the Code Project<\/h2>\n<p>This was an example on Classes in Python.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/> You can download the full source code of this example here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/03\/python_class.zip\"><strong>python-classes<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we&#8217;ll talk about classes. By using Python 3.4, we will talk about what classes are, how do we use them and what can we do with them. Python is an object-oriented programming language, and as such it has a class mechanism. Classes are extensible templates for creating objects, providing initial values for &hellip;<\/p>\n","protected":false},"author":109,"featured_media":1651,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[211,352,290],"class_list":["post-11679","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-class","tag-oop","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Class Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In this tutorial, we&#039;ll talk about classes. By using Python 3.4, we will talk about what classes are, how do we use them and what can we do with them.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Class Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, we&#039;ll talk about classes. By using Python 3.4, we will talk about what classes are, how do we use them and what can we do with them.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/sgvinci\" \/>\n<meta property=\"article:published_time\" content=\"2016-03-28T13:15:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-09T07:42:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sebastian Vinci\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sebastianvinci_\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sebastian Vinci\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"16 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/\"},\"author\":{\"name\":\"Sebastian Vinci\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/06a43c63e373dff2e159bbc029b405aa\"},\"headline\":\"Python Class Example\",\"datePublished\":\"2016-03-28T13:15:10+00:00\",\"dateModified\":\"2018-01-09T07:42:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/\"},\"wordCount\":2029,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"keywords\":[\"class\",\"OOP\",\"python\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/\",\"name\":\"Python Class Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"datePublished\":\"2016-03-28T13:15:10+00:00\",\"dateModified\":\"2018-01-09T07:42:31+00:00\",\"description\":\"In this tutorial, we'll talk about classes. By using Python 3.4, we will talk about what classes are, how do we use them and what can we do with them.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Class Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/06a43c63e373dff2e159bbc029b405aa\",\"name\":\"Sebastian Vinci\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g\",\"caption\":\"Sebastian Vinci\"},\"description\":\"Sebastian is a full stack programmer, who has strong experience in Java and Scala enterprise web applications. He is currently studying Computers Science in UBA (University of Buenos Aires) and working a full time job at a .com company as a Semi-Senior developer, involving architectural design, implementation and monitoring. He also worked in automating processes (such as data base backups, building, deploying and monitoring applications).\",\"sameAs\":[\"http:\/\/www.webcodegeeks.com\/\",\"https:\/\/www.facebook.com\/sgvinci\",\"https:\/\/x.com\/sebastianvinci_\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/sebastian-vinci\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Class Example - Web Code Geeks - 2026","description":"In this tutorial, we'll talk about classes. By using Python 3.4, we will talk about what classes are, how do we use them and what can we do with them.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/","og_locale":"en_US","og_type":"article","og_title":"Python Class Example - Web Code Geeks - 2026","og_description":"In this tutorial, we'll talk about classes. By using Python 3.4, we will talk about what classes are, how do we use them and what can we do with them.","og_url":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/sgvinci","article_published_time":"2016-03-28T13:15:10+00:00","article_modified_time":"2018-01-09T07:42:31+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","type":"image\/jpeg"}],"author":"Sebastian Vinci","twitter_card":"summary_large_image","twitter_creator":"@sebastianvinci_","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Sebastian Vinci","Est. reading time":"16 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/"},"author":{"name":"Sebastian Vinci","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/06a43c63e373dff2e159bbc029b405aa"},"headline":"Python Class Example","datePublished":"2016-03-28T13:15:10+00:00","dateModified":"2018-01-09T07:42:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/"},"wordCount":2029,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","keywords":["class","OOP","python"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/","url":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/","name":"Python Class Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","datePublished":"2016-03-28T13:15:10+00:00","dateModified":"2018-01-09T07:42:31+00:00","description":"In this tutorial, we'll talk about classes. By using Python 3.4, we will talk about what classes are, how do we use them and what can we do with them.","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/python\/python-class-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/python\/python-class-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/www.webcodegeeks.com\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Class Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/06a43c63e373dff2e159bbc029b405aa","name":"Sebastian Vinci","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g","caption":"Sebastian Vinci"},"description":"Sebastian is a full stack programmer, who has strong experience in Java and Scala enterprise web applications. He is currently studying Computers Science in UBA (University of Buenos Aires) and working a full time job at a .com company as a Semi-Senior developer, involving architectural design, implementation and monitoring. He also worked in automating processes (such as data base backups, building, deploying and monitoring applications).","sameAs":["http:\/\/www.webcodegeeks.com\/","https:\/\/www.facebook.com\/sgvinci","https:\/\/x.com\/sebastianvinci_"],"url":"https:\/\/www.webcodegeeks.com\/author\/sebastian-vinci\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/11679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/109"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=11679"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/11679\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/1651"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=11679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=11679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=11679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}