In Python, the variables that are declared inside the class are known as attributes. These attributes can be accessed and modified by both the class and its objects. Following are the two types of attributes - Class Attributes: The attributes that are defined globally in the class are known as class attributes and can be accessed throughout the class itself and are shared between all class instances. They can be accessed using the class name. Instance Attributes: The attributes that are defined inside the __init__() method are known as instance attributes. ... Read More
Python's, regular expressions (regex) allow us to search, extract, and manipulate patterns in strings. Sometimes, If we want to extract only numbers from a string, except decimals, then we can use re.findall() method with a specific regex pattern. The regex pattern was designed to specifically match the integer pattern. Let us first understand the regular expression used: \b\d+\b This pattern matches numbers like 10, 245, 89 but not 12.34 or 0.56 (decimals). \b : Word boundary to ensure we match standalone numbers. \d+ : One or more digits (0–9). ... Read More
Let's understand the problem statement: we need to convert a given strings to a title case, which involves capitalizing the first letter of each word while converting the remaining letters to lowercase. The following are the various ways to capitalize each word's first letter in a string - Using title() method Using capitalize() method Using upper() method Importing string module Importing regex module Capitalizing a String in a File Using the title() method to ... Read More
The Breadth-First Search (BFS) algorithm is a graph traversal algorithm that starts at the tree root and explores all nodes at the present depth before moving to the nodes at the next level. In this article, we will discuss how to check the connectivity of a graph using BFS traversal algorithm. Understanding Connectivity of a Graph A graph is said to be connected if there is a path between every pair of vertices. To check connectivity of a graph, we will try to traverse all nodes using any traversal algorithm. After completing the traversal, if there is any ... Read More
In many coding languages, when you try to combine a string with a number, the number is usually converted into a string automatically so both parts can be joined together. This is called implicit type conversion. With the + operator for contaminating a string with a numerical value, Python does not perform the implicit type conversion. Instead, it throws an error (specifically a TypeError) because it expects both operands to be strings. The following are the various methods to do it: Using the str() Function Using f-strings ... Read More
Using Python, we can easily search for specific types of files from a mixed list of file names using regular expressions. For this, we need to import Python’s built-in module called re using the import keyword. The Regular expression or Regex is a special sequence of characters like \, *, ^, etc, which are used to search for a pattern in a string or a set of strings. It can detect the presence or absence of characters by matching them with a particular pattern and can also split a string into one or more substrings. The following is a syntax ... Read More
Usually, if we need to find a particular word such as, "data" in a text or a string we will directly search for it. We can also use a sequence of characters which forms a pattern to search for words in a string. For example the characters "[0-9]" matches a single digit number and "[0-9]+" matches any string containing one or more digits. These sequence of characters are known as regular expressions. Groups in Python Regular Expressions Like any other programming Python provides a module named re to handle regular expressions. The methods re.match() and re.search() of this module are ... Read More
In Python, especially in situations like iterating through data structures, working with built-in functions, or fetching records from a database, lists of tuples are returned by the pre-defined functions instead of a list of lists. This is because tuples are immutable i.e., we cannot modify them after creation, whereas lists are mutable; once obtained, we can change their contents. This makes tuples ideal for storing fixed data like database records or function results, ensuring data integrity. Let us see methods/functions in Python that return a list of tuples - The enumerate() Function The enumerate() function is used to add a counter to ... Read More
Installing Python Modules on Mac Managing Python packages efficiently is important for developers; this can be challenging, especially while working on macOS. In this article, there will be a list of different options to install Python modules on a Mac from which you could choose one that is reliable and easy to use. Some common ways to install Python modules in macOS are listed below - Using EasyInstall Using Pip Using Homebrew Using Virtual Environment Using EasyInstall The most popular way to ... Read More
In this article, we will learn about the importance of the Cursor class in Java. Under the Swing toolkit, the Cursor class provides an improved user experience by providing graphical(visual) feedback. What is a Cursor class? A Cursor is a subclass of the Object class, and it can be defined as point or indicator on the screen. A Cursor is used to select the input from the system that the user operates with the mouse. The important methods of Cursor class are getDefaultCursor(), getName(), getPredefinedCursor(), getSystemCustomCursor(), and getType(). Syntax The following is the syntax: Cursor cursor = new Cursor(Type_of_Cursor); Different ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP