Mohd Mohtashim has Published 251 Articles

Regular Expression Patterns in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 07:36:37

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

Regular Expression Modifiers in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 07:35:43

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

Search and Replace in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 07:32:26

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

Matching Versus Searching in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 07:31:11

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

The search Function in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 07:30:15

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

Base Overloading Methods in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 07:22:55

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

Overloading Operators in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 07:21:12

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

Destroying Objects (Garbage Collection) in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 07:16:43

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

Creating Classes in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 07:09:31

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

OOP Terminology in Python

Mohd Mohtashim

Mohd Mohtashim

Updated on 30-Jan-2020 07:08:18

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

Previous 1 ... 3 4 5 6 7 ... 26 Next
Advertisements