- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 452 Articles
Rajendra Dharmkar
354 Views
The __str__ method__str__ is a special method, like __init__, that returns a 'informal' string representation of an object. It is useful in debugging.Consider the following code that uses the __str__ methodclass Time: def __str__(self): return '%.2d:%.2d:%.2d' % (self.hour, self.minute, self.second)When we print an object, ... Read More
Rajendra Dharmkar
552 Views
The official Python documentation says __repr__() is used to compute the “official” string representation of an object. The repr() built-in function uses __repr__() to display the object. __repr__() returns a printable representation of the object, one of the ways possible to create this object. __repr__() is more useful for developers ... Read More
Rajendra Dharmkar
223 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
555 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
388 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
Rajendra Dharmkar
258 Views
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
Rajendra Dharmkar
5K+ Views
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
Rajendra Dharmkar
193 Views
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
Rajendra Dharmkar
273 Views
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
Rajendra Dharmkar
1K+ Views
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