In this article, we will see how we can create empty functions in Python. A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. Function blocks begin with the keyword def followed by the function name and parentheses (). Here, we will see examples of empty functions using the pass statement. What is the pass Statement? The pass statement is a null operation in Python. It does nothing when executed and serves as a placeholder ... Read More
The reload() function is used to reload a previously imported module. This is particularly useful during interactive development sessions where you modify a module's code and want to see changes without restarting the Python interpreter. When you modify a module file after importing it, Python continues to use the cached version. The reload() function forces Python to re-read and re-execute the module code. How reload() Works When reload() is executed, several important things happen: The module's code is recompiled and re-executed, creating new objects bound to names in the module's dictionary Old objects are only ... Read More
Python provides two types of operators: inplace operators that modify variables directly, and standard operators that create new values. Understanding the difference helps you write more efficient code. Inplace Operators Inplace operators modify the original variable without creating a copy. They use compound assignment syntax like +=, -=, etc. Basic Example a = 9 a += 2 print(a) 11 The += operator adds 2 to the original value of a and updates it in place. Common Inplace Operators += (addition) -= (subtraction) *= (multiplication) /= (division) %= ... Read More
In Python, variables have different scopes that determine where they can be accessed. There are two main types: global variables (accessible throughout the entire program) and local variables (accessible only within the function where they are defined). Local Variables Local variables are created inside a function and can only be accessed within that function. They exist only during the function's execution ? def my_function(): x = "Python" # Local variable print("Inside function:", x) my_function() # print(x) # This would cause NameError Inside ... Read More
Python provides a comprehensive library to read, represent and manipulate time information through the time module. Date, time and datetime are objects in Python, so whenever we perform operations on them, we work with objects rather than strings or timestamps. The time module follows the EPOCH convention, which refers to the starting point for time calculations. In Unix systems, EPOCH time started from January 1, 1970, 12:00 AM UTC. Understanding EPOCH Time To determine the EPOCH time value on your system ? import time print(time.gmtime(0)) time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, ... Read More
Transpose a matrix means we're turning its columns into its rows. Let's understand it by an example what it looks like after the transpose. Let's say you have original matrix something like − matrix = [[1, 2], [3, 4], [5, 6]] print(matrix) [[1, 2], [3, 4], [5, 6]] In above matrix we have two columns, containing 1, 3, 5 and 2, 4, 6. So when we transpose above matrix, the columns becomes the rows. So the transposed version would look something like − [[1, 3, 5], [2, 4, 6]] ... Read More
Internet Protocol is currently in the process of moving from version 4 to version 6. This is necessitated because version 4 doesn't provide enough addresses to handle the increasing number of devices with direct connections to the internet. An IPv4 address is composed of 32 bits, represented into four eight-bit groups called "octets". This is a "dotted decimal" format where each eight-bit octet can have a decimal value 0 to 255. For example: 192.168.1.1 IPv4 address with CIDR notation: 192.168.1.1/24 where 24 means first three octets identify the network and last octet identifies node. An IPv6 ... Read More
Web site owners use the /robots.txt file to give instructions about their site to web robots; this is called The Robots Exclusion Protocol. This file is a simple text-based access control system for computer programs that automatically access web resources. Such programs are called spiders, crawlers, etc. The file specifies the user agent identifier followed by a list of URLs the agent may not access. Example robots.txt File #robots.txt Sitemap: https://example.com/sitemap.xml User-agent: * Disallow: /admin/ Disallow: /downloads/ Disallow: /media/ Disallow: /static/ This file is usually put in the top-level directory of your web server. ... Read More
The urllib.parse module provides a standard interface to break Uniform Resource Locator (URL) strings into 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: file ftp gopher hdl http https imap mailto mms ... Read More
The html.parser module in Python's standard library provides the HTMLParser class for parsing HTML and XHTML documents. This class contains handler methods that can identify tags, data, comments, and other HTML elements. To use HTMLParser, create a subclass that inherits from HTMLParser and override specific handler methods to process different HTML elements. Basic HTMLParser Setup Here's the basic structure for creating a custom HTML parser ? from html.parser import HTMLParser class MyParser(HTMLParser): pass parser = MyParser() parser.feed('') Handling Start Tags The handle_starttag(tag, attrs) method is called ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance