- 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
Mohd Mohtashim has Published 251 Articles
Mohd Mohtashim
386 Views
Except for control characters, (+ ? . * ^ $ ( ) [ ] { } | \), all characters match themselves. You can escape a control character by preceding it with a backslash.Following table lists the regular expression syntax that is available in Python −Sr.No.Pattern & Description1^Matches beginning of ... Read More
Mohd Mohtashim
1K+ Views
Regular expression literals may include an optional modifier to control various aspects of matching. The modifiers are specified as an optional flag. You can provide multiple modifiers using exclusive OR (|), as shown previously and may be represented by one of these −Sr.No.Modifier & Description1re.IPerforms case-insensitive matching.2re.LInterprets words according to ... Read More
Mohd Mohtashim
165 Views
One of the most important re methods that use regular expressions is sub.Syntaxre.sub(pattern, repl, string, max=0)This method replaces all occurrences of the RE pattern in string with repl, substituting all occurrences unless max provided. This method returns modified string.Example Live Demo#!/usr/bin/python import re phone = "2004-959-559 # This is Phone Number" # Delete Python-style comments ... Read More
Mohd Mohtashim
1K+ Views
Python offers two different primitive operations based on regular expressions: match checks for a match only at the beginning of the string, while search checks for a match anywhere in the string (this is what Perl does by default).Example Live Demo#!/usr/bin/python import re line = "Cats are smarter than dogs"; matchObj ... Read More
Mohd Mohtashim
2K+ Views
This function searches for first occurrence of RE pattern within string with optional flags.SyntaxHere is the syntax for this function −re.search(pattern, string, flags=0)Here is the description of the parameters −Sr.No.Parameter & Description1patternThis is the regular expression to be matched.2stringThis is the string, which would be searched to match the pattern at the beginning of string.3flagsYou ... Read More
Mohd Mohtashim
341 Views
Following table lists some generic functionality that you can override in your own classes −Sr.No.Method, Description & Sample Call1__init__ ( self [, args...] )Constructor (with any optional arguments)Sample Call : obj = className(args)2__del__( self )Destructor, deletes an objectSample Call : del obj3__repr__( self )Evaluable string representationSample Call : repr(obj)4__str__( self ... Read More
Mohd Mohtashim
270 Views
Suppose you have created a Vector class to represent two-dimensional vectors, what happens when you use the plus operator to add them? Most likely Python will yell at you.You could, however, define the __add__ method in your class to perform vector addition and then the plus operator would behave as per expectation ... Read More
Mohd Mohtashim
742 Views
Python deletes unneeded objects (built-in types or class instances) automatically to free the memory space. The process by which Python periodically reclaims blocks of memory that no longer are in use is termed Garbage Collection.Python's garbage collector runs during program execution and is triggered when an object's reference count reaches ... Read More
Mohd Mohtashim
2K+ Views
The class statement creates a new class definition. The name of the class immediately follows the keyword class followed by a colon as follows −class ClassName: 'Optional class documentation string' class_suiteThe class has a documentation string, which can be accessed via ClassName.__doc__.The class_suite consists of all the component statements defining class members, data ... Read More
Mohd Mohtashim
2K+ Views
Class − A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation.Class variable − A variable that is shared by all instances of a class. ... Read More