- 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
Found 10784 Articles for Python
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
114 Views
We can derive a class from multiple parent classes as follows −class A: # define your class A ..... class B: # define your class B ..... class C(A, B): # subclass of A and B .....We can use issubclass() function to check the relationships of two classes and instances.For example, theissubclass(sub, sup) boolean function returns true if the given subclass sub is indeed a subclass of the superclass sup.
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
166 Views
Inheritance in classesInstead of defining a class afresh, we can create a class by deriving it from a preexisting class by listing the parent class in parentheses after the new class name.The child class inherits the attributes of its parent class, and we can use those attributes as if they were defined in the child class. A child class can also override data members and methods from the parent.SyntaxDerived classes are declared much like their parent class; however, a list of base classes to inherit from is given after the class name −class SubClassName (ParentClass1[, ParentClass2, ...]): 'Optional class ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
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 count reaches zero. An object's reference count changes as the number of aliases that point to it changes.An object's reference count increases when it is assigned a new name or placed in a container (list, tuple, or dictionary). The object's reference count decreases when it's deleted with del, its reference is ... Read More
![Sarika Singh](https://www.tutorialspoint.com/assets/profiles/502778/profile/60_2211036-1660719373.jpg)
19K+ Views
When an object is deleted or destroyed, a destructor is invoked. Before terminating an object, cleanup tasks like closing database connections or filehandles are completed using the destructor. The garbage collector in Python manages memory automatically. for instance, when an object is no longer relevant, it clears the memory. In Python, the destructor is entirely automatic and never called manually. In the following two scenarios, the destructor is called − When an object is no longer relevant or it goes out of scope The object's reference counter reaches zero. Using the __del__() method In Python, a destructor is ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
524 Views
A class attribute is an attribute of the class rather than an attribute of an instance of the class.In the code below class_var is a class attribute, and i_var is an instance attribute: All instances of the class have access to class_var, which can also be accessed as a property of the class itself −Exampleclass MyClass (object): class_var = 2 def __init__(self, i_var): self.i_var = i_var foo = MyClass(3) baz = MyClass(4) print (foo.class_var, foo.i_var) print (baz.class_var, baz.i_var)OutputThis gives the output(2, 3) (2, 4)
![Malhar Lathkar](https://www.tutorialspoint.com/assets/profiles/7345/profile/60_93814-1511173378.jpg)
172 Views
Python tuple is an immutable object. Hence any operation that tries to modify it (like append/insert) is not allowed. However, following workaround can be used.First, convert tuple to list by built-in function list(). You can always append as well as insert an item to list object. Then use another built-in function tuple() to convert this list object back to tuple.>>> T1=(10,50,20,9,40,25,60,30,1,56) >>> L1=list(T1) >>> L1 [10, 50, 20, 9, 40, 25, 60, 30, 1, 56] >>> L1.append(100) >>> L1.insert(4,45) >>> T1=tuple(L1) >>> T1 (10, 50, 20, 9, 45, 40, 25, 60, 30, 1, 56, 100)
![Sarika Singh](https://www.tutorialspoint.com/assets/profiles/502778/profile/60_2211036-1660719373.jpg)
121K+ Views
Tuples in Python are immutable, meaning that once they are created, their contents cannot be changed. However, there are situations when we want to change the existing tuple, in which case we must make a new tuple using only the changed elements from the original tuple. Following is the example of the tuple − s = (4, 5, 6) print(s) print(type(s)) Following is the output of the above code − (4, 5, 6) Tuple is immutable, although you can use the + operator to concatenate several tuples. The old object is still present at this point, and ... Read More
![Malhar Lathkar](https://www.tutorialspoint.com/assets/profiles/7345/profile/60_93814-1511173378.jpg)
299 Views
Slicing operator can be used with any sequence data type, including Tuple. Slicing means separating a part of a sequence, here a tuple. The symbol used for slicing is ‘:’. The operator requires two operands. First operand is the index of starting element of slice, and second is index of last element in slice+1. Resultant slice is also a tuple.>>> T1=(10,50,20,9,40,25,60,30,1,56) >>> T1[2:4] (20, 9)Both operands are optional. If first operand is missing, slice starts from beginning. If second operand is missing, slice goes upto end.>>> T1=(10,50,20,9,40,25,60,30,1,56) >>> T1[6:] (60, 30, 1, 56) >>> T1[:4] (10, 50, 20, 9)
![Pythonic](https://www.tutorialspoint.com/assets/profiles/15007/profile/60_156531-1514381552.jpg)
3K+ Views
By definition, tuple object is immutable. Hence it is not possible to remove element from it. However, a workaround would be convert tuple to a list, remove desired element from list and convert it back to a tuple.>>> T1=(1,2,3,4) >>> L1=list(T1) >>> L1.pop(0) 1 >>> L1 [2, 3, 4] >>> T1=tuple(L1) >>> T1 (2, 3, 4)
![Pythonic](https://www.tutorialspoint.com/assets/profiles/15007/profile/60_156531-1514381552.jpg)
137 Views
The built-in functions repr() and str() respectively call object.__repr__(self) and object.__str__(self) methods. First function computes official representation of the object, while second returns informal representation of the object. Result of both functions is same for integer object. >>> x = 1 >>> repr(x) '1' >>> str(x) '1' However, it is not the case for string object. >>> x = "Hello" >>> repr(x) "'Hello'" >>> str(x) 'Hello' Return value of repr() of a string object can be evaluated by eval() function and results in valid string object. However, result of str() can not be evaluated. ... Read More