Found 33676 Articles for Programming

urllib.parse — Parse URLs into components in Python

Nitya Raut
Updated on 30-Jul-2019 22:30:25

8K+ Views

This module provides a standard interface to break Uniform Resource Locator (URL) strings in components or to combine the components back into a URL string. It also has functions to convert a "relative URL" to an absolute URL given a "base URL."This module supports the following URL schemes -fileftpgopherhdlhttphttpsimapmailtommsnewsnntpprosperorsyncrtsprtspusftpshttpsipsipssnewssvnsvn+sshtelnetwaiswswssurlparse()This function parses a URL into six components, returning a 6-tuple. This corresponds to the general structure of a URL. Each tuple item is a string. The components are not broken up in smaller parts (for example, the network location is a single string), and % escapes are not expanded. The return ... Read More

html.parser — Simple HTML and XHTML parser in Python

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

2K+ Views

The HTMLParser class defined in this module provides functionality to parse HTML and XHMTL documents. This class contains handler methods that can identify tags, data, comments and other HTML elements.We have to define a new class that inherits HTMLParser class and submit HTML text using feed() method.from html.parser import HTMLParser class parser(HTMLParser): pass p = parser() p.feed('')We have to override its following methodshandle_starttag(tag, attrs):HTML tags normally are in pairs of starting tag and end tag. For example and . This method is called to handle the start of a tag.Name of the tag converted to lower case. The attrs ... Read More

Functools — Higher-order functions and operations on callable objects in Python

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

257 Views

Function in Python is said to be of higher order. It means that it can be passed as argument to another function and/or can return other function as well. The functools module provides important utilities for such higher order functions.partial() functionThis function returns a callable 'partial' object. The object itself behaves like a function. The partial() function receives another function as argument and freezes some portion of a function’s arguments resulting in a new object with a simplified signature.The built-in int() function converts a number to a decimal integer. Default signature of int() isint(x, base = 10)The partial() function can ... Read More

Copy - Shallow and deep copy operations in Python

Akshitha Mote
Updated on 12-Dec-2024 19:22:29

932 Views

What is a Copy Operation in Python? Copying in Python refers to the process of creating a duplicate of existing data. The simplest way to create a reference to an object is by using the assignment operator (=), but this does not create an actual copy—it only makes the new variable point to the same object in memory. To create an independent copy, Python provides two methods: shallow copy and deep copy, which can be achieved using the copy module. The Assignment operator doesn't create a new object; instead, it binds a new variable to the same memory address ... Read More

Bisect - Array bisection algorithm in Python

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

692 Views

Performing sort operations after every insertion on a long list may be expensive in terms of time consumed by processor. The bisect module ensures that the list remains automatically sorted after insertion. For this purpose, it uses bisection algorithm. The module has following functions:bisect_left()This method locates insertion point for a given element in the list to maintain sorted order. If it is already present in the list, the insertion point will be before (to the left of) any existing entries. The return value caan be used as the first parameter to list.insert()bisect_right()This method is similar to bisect_left(), but returns an ... Read More

Array — Efficient arrays of numeric values in Python

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

324 Views

Array is a very popular data structure in C/C++, Java etc. In these languages array is defined as a collection of more than one elements of similar data type. Python doesn't have any built-in equivalent of array. It's List as well as Tuple is a collection of elements but they may of different types.Python's array module emulates C type array. The module defines 'array' class. Following constructor creates an array object:array(typecode, initializer)The typecode argument determines the type of array. Initializer should be a sequence with all elements of matching type.Following statement creates an integer array object:>>> import array >>> arr ... Read More

RTTI (Run-time type Information) in C++ program

Aman Kumar
Updated on 15-May-2025 15:39:38

2K+ Views

In C++, RTTI (Run-time type information) is a process that disclose information about an object data types at runtime and available one for the classes that have at least one virtual function. It allow the type of an object to be determine during the program execution. Runtime Casts The runtime cast checks that the cast is valid. It is the simplest approach to confirm the runtime type of an object using a pointer or reference. It is especially beneficial when we cast a pointer from a base class to a derived type. There are two types of casting: ... Read More

Copy elision in C++

Nitya Raut
Updated on 30-Jul-2019 22:30:25

226 Views

The Copy Elision is also known as the Copy Omission. This is one of the compiler optimization technique. It avoids the unnecessary copying of objects. Almost any current compiler uses this Copy Elision technique.Let us see how it works by the help of one example code:Example Code#include using namespace std; class MyClass {    public:       MyClass(const char* str = "\0") {  //default constructor          cout

How to Parse Command Line Arguments in C++?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

581 Views

It is possible to pass some values from the command line to your C++ programs when they are executed. These values are called command line arguments and many times they are important for your program especially when you want to control your program from outside instead of hard-coding those values inside the code.The command line arguments are handled using main() function arguments where argc refers to the number of arguments passed, and argv[] is a pointer array which points to each argument passed to the program. Following is a simple example which checks if there is any argument supplied from ... Read More

What does the operation c=a+++b mean in C/C++?

Aman Kumar
Updated on 30-Jul-2025 15:03:20

2K+ Views

In C/C++, the expression c = a++ + b indicates that the current value of a is added to b, and the result is assigned to c. After this assignment, a is incremented by 1 (post-increment), which means the increment of a happens after its value is used in the expression. Well, let a and b initialize with 2 and 5, respectively. This expression can be taken as two different types. c = (a++) + b c = a + (++b) The above two expressions contain both post and pre-increment ... Read More

Advertisements