Rajendra Dharmkar has Published 504 Articles

Introduction to Classes and Inheritance in Python

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 13-Jun-2020 14:01:31

Object-oriented programming creates reusable patterns of code to prevent code redundancy in projects. One way that recyclable code is created is through inheritance, when one subclass leverages code from another base class.Inheritance is when a class uses code written within another class.Classes called child classes or subclasses inherit methods and ... Read More

How do we check if a class is a subclass of the given super class in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 13-Jun-2020 13:52:45

We have the classes A and B defined as follows −class A(object): pass class B(A): passB can be proved to be a sub class of A in two ways as followsclass A(object):pass class B(A):pass print issubclass(B, A) # Here we use the issubclass() method to check if B is subclass ... Read More

How does garbage collection work in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 13-Jun-2020 13:25:47

Python deletes unwanted objects (built-in types or class instances) automatically to free the memory space. The process by which Python periodically frees and reclaims blocks of memory that no longer are in use is called Garbage Collection.Python's garbage collector runs during program execution and is triggered when an object's reference ... Read More

What does hasattr() function do in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 13-Jun-2020 08:44:28

The hasattr() method in PythonThe hasattr() method returns true if an object has the given named attribute and false if it does not.SyntaxThe syntax of hasattr() method is −hasattr(object, name)The hasattr() is called by getattr() to check to see if AttributeError is to be raised or not.The hasattr() method takes ... Read More

What does getattr() function do in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 13-Jun-2020 08:43:32

Python getattr()The getattr() method returns the value of the named attribute of an object. If not found, it returns the default value provided to the function.SyntaxThe syntax of getattr() method is −getattr(object, name[, default])The getattr() method can take multiple parameters −The getattr() method returns −value of the named attribute of ... Read More

Explain the variables inside and outside of a class __init__() function in Python.

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 13-Jun-2020 08:42:06

Class variables vs Instance VariablesAll variables outside the class __init__ function in Python are class variables while those inside the same are instance variables. The difference between the class variables and instance variables is understood better by examining the code belowExampleclass MyClass:     stat_elem = 456     def ... Read More

What is difference between self and __init__ methods in python Class?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 13-Jun-2020 08:30:30

selfThe word 'self' is used to represent the instance of a class. By using the "self" keyword we access the attributes and methods of the class in python.__init__ method"__init__" is a reseved method in python classes. It is called as a constructor in object oriented terminology. This method is called ... Read More

How to create instance Objects using __init__ in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 13-Jun-2020 08:29:40

The instantiation or calling-a-class-object operation creates an empty object. Many classes like to create objects with instances with a specific initial state. Therefore a class may define a special method named __init__(), as follows −def __init__(self) −    self.data = [ ]When a class defines an __init__() method, class instantiation ... Read More

Explain briefly the Object oriented concepts in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 13-Jun-2020 08:25:05

OOP concepts in PythonPython is an object-oriented programming language. We can easily create and use classes and objects in Python.Major object-oriented concepts of Python programming language are given below −ObjectClassMethodInheritancePolymorphismData AbstractionEncapsulationObjectObject is an entity that has state and behaviour. It may be physical and logical. For example: mouse, keyboard, chair, ... Read More

How do you validate a URL with a regular expression in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 13-Jun-2020 07:28:42

There's no validate method as almost anything is a valid URL. There are some punctuation rules for splitting it up. Without any punctuation, you still have a valid URL.Depending on the situation, we use following methods.If you trust the data, and just want to verify if the protocol is HTTP, ... Read More

Previous 1 ... 7 8 9 10 11 ... 51 Next
Advertisements