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…


Python global variable in class | Example code

If a variable declared outside of the function or in global scope is called a global variable in Python. If it’s defined inside the class but not in any function then still it will available to other members. Python global variable in class example Simple example code Global variables can be used inside of functions Read More…


How to access class variable in Python | Example code

Use class_name dot variable_name to access a class variable from a class method in Python. Use instance to access variables outside the class. Example access a class variable in Python Simple example code. A class variable is a variable that is shared by all objects of the same class. Output: How to access variables from Read More…


Python objects | Basic

Python object is created using the class name. A python is an object-oriented programming language. Where objects are simply a collection of attributes (variables) and functions. Syntax Python objects examples Simple example code created the object of MyClass class. Output: Accessing variable using object The variables that belong to a class and are always public, Read More…


Python class | Basics

Use class keywords to create user define objects in Python. Python class is a blueprint (prototype from which objects are created) for features and methods of objects. A python is an object-oriented programming language. Everything is in Python treated as an object, including variable, function, list, tuple, dictionary, set, etc. An object is simply a Read More…


Python type function | Get object type

Python type function is used to get the type of object. This function with one argument, return the type of an object. The type() function is mostly developers use it for debugging purposes. Syntax Note: The isinstance() function is recommended for check the type of an object because it takes subclasses into account. Example type Read More…




Python boolean if statement | Example codes

Booleans represent one of two values: True or False. Is used in if statement in Python. If it’s true execute the block of code or else skip it. Note: don’t forget capital T and F, it is case sensitive Example boolean if in Python Let’s check if boolean is true Python Output: More boolean Python Read More…