Server Side Programming Articles

Page 643 of 2109

How does * operator work on list in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 18K+ Views

In Python, a list is an ordered sequence that can hold several object types such as integer, character, or float. The * operator has special behavior when used with lists, performing repetition instead of multiplication. This article demonstrates how the * operator works on lists in Python through practical examples and different use cases. Basic List Repetition The * operator creates multiple copies of a list and joins them together. When you multiply a list by an integer n, Python repeats the entire list n times ? # Creating a simple list numbers = [1, ...

Read More

How to sort the objects in a list in Python?

Vikram Chiluka
Vikram Chiluka
Updated on 24-Mar-2026 2K+ Views

In Python, a list is an ordered sequence that can hold several object types such as integer, character, or float. In other programming languages, a list is equivalent to an array. Square brackets are used to denote it, and a comma (, ) is used to divide two items in the list. In this article, we will show you how to sort the objects and elements in a list using Python. Below are the different methods to accomplish this task − Using sort() method Using sorted() method Assume we have taken a list containing some ...

Read More

What are character classes or character sets used in Python regular expression?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 2K+ Views

In this chapter, we will understand character classes, how they work, and provide simple examples and programs to explain their usage. One of the main components of regular expressions is character classes or character sets. Character classes help you to define a set of characters that will match in a string. They can be used to define a range of characters or specific characters to consider during a search. Character Classes or Character Sets A character class, also known as a character set, helps you inform the regex engine to match only one of numerous characters. Simply ...

Read More

How to write Python regular expression to get zero or more occurrences within the pattern?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 1K+ Views

In this article we will be using Regular Expression to get zero or more occurrences within the pattern. Regular expressions (regex) are important features to identify patterns in text. In Python, the re module provides support for working with regex. The concept of zero or more occurrences is a key regex feature that allows a pattern to appear anywhere from zero to infinite times. Understanding Zero or More Occurrences In regex, the * symbol denotes zero or more instances of the preceding element. For example, the pattern a* will match ? ...

Read More

What Python regular expression can be used in place of string.replace?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 279 Views

In this article, we are going to discuss how to use regular expressions in place of the string.replace() method. As you may know, Python's built-in string.replace() method is used to replace given substrings in a string. But when we need more complex replacement features, Python's re (regular expressions) module is very helpful. Regular expressions allow us to search for patterns and replace them with precise values, which makes string manipulation simpler and more flexible. Why Use Regular Expressions? While string.replace() works well for simple tasks, it has its limitations. It can only replace exact substrings and has ...

Read More

How does B regular expression work in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 849 Views

Regular expressions (regex) are powerful tools for pattern matching in strings. Python's re module provides comprehensive support for working with regex patterns to search, match, and manipulate text data. Understanding Regular Expressions in Python Regular expressions are sequences of characters that define search patterns. They allow you to find specific patterns within strings, validate input formats, and perform complex text manipulations efficiently. Importing the re Module To use regular expressions in Python, you need to import the re module ? import re Common Regular Expression Methods Python's re module provides several ...

Read More

How you can get a true/false from a Python regular expressions?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 24-Mar-2026 5K+ Views

The re module provides tools while working with Python's regular expression (regex), which allows us to search for any specific pattern within strings. Using the re module, we can get True/False results from regular expressions by checking if pattern matching functions return a match object or None. Three main functions help achieve this ? re.match(): Checks if the pattern matches the beginning of the string. re.search(): ...

Read More

How does [d+] regular expression work in Python?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 3K+ Views

Regular expressions are a useful tool for searching and manipulating strings in Python. Among the several patterns and methods available, the \d+ expression is used to match one or more digits in a string. In this article, we will go over the \d+ regular expression pattern, how it works, and provide code examples with explanations to help you understand and apply it to your Python projects. Understanding the \d+ Pattern The \d+ pattern consists of two elements ? \d: This is a ...

Read More

How to write a case insensitive Python regular expression without re.compile?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 15K+ Views

By default, Python regular expressions (regex) look for case-sensitive matches. The terms "apple" and "Apple" are treated as different patterns. However, we can perform case-insensitive matching by using the re.IGNORECASE flag directly in regex functions without needing re.compile(). Basic Syntax To make any regex function case-insensitive, add the flags=re.IGNORECASE parameter − re.function(pattern, string, flags=re.IGNORECASE) This works with re.search(), re.match(), re.findall(), re.sub(), and other regex functions. Using re.findall() with Case Insensitivity Let's find all occurrences of "python" regardless of case − import re text = "Python is a versatile programming ...

Read More

Extract decimal numbers from a string in Python

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 24-Mar-2026 14K+ Views

To extract decimal numbers from a string in Python, regular expressions are used. A regular expression is a group of characters that allows you to use a search pattern to find a string or a set of strings. RegEx is another name for regular expressions. The re module in Python is used to work with regular expressions. In this article, we will learn how to extract decimal numbers from a string in Python using regular expressions. Regular Expression Pattern To retrieve decimal numbers from a string, we use the following regular expression − \d+\.\d+ ...

Read More
Showing 6421–6430 of 21,090 articles
« Prev 1 641 642 643 644 645 2109 Next »
Advertisements