A local variable in Python | Example code

A variable declared inside the function is called a local variable in Python. Local variables are accessible only inside the function. Example local variable in Python Simple example code creates a local variable inside a function and tries to access it outside those functions. Output: shows an error (NameError) because we are trying to access Read More…


How to declare private variable in Python | Example code

Python does not have any private variables as Java does. Access member variable is available in Python. However, don’t need private variables in Python, because it’s not bad to expose your classes member variables. The double underscore “__” does not mean a “private variable”. Use it to define variables that are “class local” and which Read More…



Super keyword in Python? | Example

There is no super keyword instead Super function is used in Python to give access to methods and properties of a parent or sibling class. Syntax This function returns an object that represents the parent class. Example Super keyword function in Python Simple example codes the class that will inherit all the methods and properties Read More…


Python multiple constructors | Example code

In Python, you can’t define multiple constructors. However, you can define a default value if one is not passed. Way to Achieve Multiple Constructors in Python Multiple constructors come to use when a defined class has to perform different functions. You can do Python Constructor overloading based on arguments as Multiple Constructors. Do if-elif blocks Read More…


Private members in Python | Example code

Python doesn’t have any mechanism that effectively restricts access to Private Members like instance variables or methods. Using prefix single or double underscore in a method or variable name to emulate the behavior of protected and private access specifiers. Example Private members in Python Simple example code to make private members. Use double underscore __ Read More…


Parameterized constructor in Python | Example code

A constructor with a Parameter is called Parameterized constructor in Python. Parameters could be one, two, or more. Example Parameterized constructor in Python Simple example code accepts the arguments during object creation then such types of constructors are known as Parameterized constructors. We can pass the values (data) during object creation. It will set custom Read More…


Python class instance variables

In the Python class, if variables values are assigned inside methods are called instance variables. Instance variables can have different values across multiple instances of a class. Python class instance variables example Simple example code declared Instance variables inside a class method and print the values after creating an object. Create an instance of our Read More…