
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
Programming Articles - Page 3252 of 3366

219 Views
In Python, the declarations within a class are not equivalent to those within the __init__() method. Let's discuss the class and __init__() method. A class is a collection of objects. It contains the blueprints or the prototype from which the objects are being created. It is a logical entity that contains some attributes and methods. Python '__init__()' The Python __init__() function is one of the OOP's concepts. The __init__() is called automatically whenever the object is been created to a class. The __init__() function is also known as a constructor. Constructors are used to initialize ... Read More

321 Views
Django is one of the frameworks used along with python to create the web pages in an efficient manner. It is also called as the framework included with batteries why because by default the Django framework gives the admin interface and database interface like SQLite 3 etc. It also provides us the default readymade components namely user authentication handling like sign in, signup and sign out. It provides the management panel for our website, forms, uploading the files etc. Why are we using the Django framework? Django is known for its scalability and comprehensive documentation. This framework is used by ... Read More

2K+ Views
OOPs is abbreviated as object oriented programming language. It helps us to deal with the real time entities with inheritance, polymorphism, encapsulation etc. By using the oops concept we can make the code and functions work together in a better way. Group of objects is called a class. The class contains the blueprint, which takes as the reference to create the object. This contains attributes and methods in a logical entity. Now let’s see why we have to split the code into multiple classes. If we create the entire code in the single class, it will be easy to write ... Read More

1K+ Views
There are different modules or packages in the python classes. When we use their names as it is in the code it will be somewhat clumsy and not good to see. So, we need to organize the python classes in modules and packages. Modules are the group of functions, classes or any block of code kept in a single file. The file extension of the methods will be .py. If the python code is with 300-400 lines of code, then it can be made as a module for better understandability. The module name can be available as ... Read More

1K+ Views
Encapsulation is one of the fundamental concepts in object-oriented programming (OOP). It describes the idea of wrapping data and the methods that work on data within one unit. This restricts accessing variables and methods directly and can prevent the accidental modification of data. To prevent accidental change, an object’s variable can only be changed by the object’s method. Those types of variables are known as private variables. In Python, getters and setters are methods used to access and modify private attributes of a class. These methods are ... Read More

898 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 = getattr(m, comp) return mm is the classWe can instantiate this class as followsa = m() b = m(arg1, arg2) # passing args to the constructor

11K+ Views
In Python, inheritance is the capability of one class to derive or inherit the properties from another class. The class that derives properties is called the derived class or child class, and the class from which the properties are being derived is called the base class or parent class. In other words, inheritance refers to defining a new class with little or no modification to an existing class. Following is the syntax of the inheritance - class A: #class A (base class) pass class ... Read More

235 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', )]

13K+ Views
Let's understand the title: converting a string to a Python class means accessing a Python class using its name stored as a string, allowing dynamic creation of objects at runtime. In this article, we will discuss different ways to convert a string to a Python class object. Using globals() Function The globals() function is used to convert a string to a Python class object when a class is in global scope. class Bike: def start(self): print("Bike started!") class_name = "Bike" cls = globals()[class_name] # Convert string to class obj ... Read More

1K+ Views
We can use python-jsonschema-objects which is built on top of jsonschema.The python-jsonschema-objects provide an automatic class-based binding to JSON schemas for use in Python.We have a sample json schema as followsschema = '''{ "title": "Example Schema", "type": "object", "properties": { "firstName": { "type": "string" }, "lastName": { "type": "string" }, "age": { "description": "Age in years", ... Read More