
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Rajendra Dharmkar has Published 189 Articles

Rajendra Dharmkar
882 Views
To instantiate the python class, we need to get the class name first. This is achieved by following codedef get_class( kls ): parts = kls.split('.') module = ".".join(parts[:-1]) m = __import__( module ) for comp in parts[1:]: m ... Read More

Rajendra Dharmkar
198 Views
In Python 2.x there are two styles of classes depending on the presence or absence of a built-in type as a base-class −‘Old style’ or "Classic" style classes: they have no built-in type as a base class −>>> class OldFoo: # no base class ... pass ... Read More

Rajendra Dharmkar
330 Views
The code below shows the if the attribute 'foo' was defined or derived in the classes A and B.Exampleclass A: foo = 1 class B(A): pass print A.__dict__ #We see that the attribute foo is there in __dict__ of class A. So foo is defined in ... Read More

Rajendra Dharmkar
228 Views
The following code prints the list of functions of the given class as followsExampleclass foo: def __init__(self): self.x = x def bar(self): pass def baz(self): pass print (type(foo)) import inspect print(inspect.getmembers(foo, predicate=inspect.ismethod))OutputThe output is [('__init__', ), ('bar', ), ('baz', )]

Rajendra Dharmkar
651 Views
In Python 2.x there's two styles of classes depending on the presence or absence of a built-in type as a base-class −"classic" style or old style classes have no built-in type as a base class: >>> class OldSpam: # no base class ... pass >>> OldSpam.__bases__ ... Read More

Rajendra Dharmkar
4K+ Views
Data hidingIn Python, we use double underscore before the attributes name to make them inaccessible/private or to hide them.The following code shows how the variable __hiddenVar is hidden.Exampleclass MyClass: __hiddenVar = 0 def add(self, increment): self.__hiddenVar += increment print (self.__hiddenVar) ... Read More

Rajendra Dharmkar
478 Views
The cmp() functionThe cmp(x, y) function compares the values of two arguments x and y −cmp(x, y)The return value is −A negative number if x is less than y.Zero if x is equal to y.A positive number if x is greater than y.The built-in cmp() function will typically return only ... Read More

Rajendra Dharmkar
354 Views
Assuming you have set up Python 3.6, Pipenv and heroku CLI installed locally and are logged in on Heroku from the CLI using the steps mentioned here: https://devcenter.heroku.com/articles/getting-started-with-python#set-up.Your application needs to have a git repository to be deployed to heroku. You need to cd in the directory where the root ... Read More

Rajendra Dharmkar
731 Views
You can use dictionaries to interpolate strings. They have a syntax in which you need to provide the key in the parentheses between the % and the conversion character. For example, if you have a float stored in a key 'cost' and want to format it as '$xxxx.xx', then you'll ... Read More

Rajendra Dharmkar
445 Views
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