
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33581 Articles for Programming

4K+ Views
In programming, a substring is a smaller part of the string. Extracting the substring is a task in Python, whether we are analysing the user input or manipulating URLs, we will find ourself to grab a portion of the string. For achieving, Python provides the various way, Let's dive into the article to learn more about extracting the substring from the string. Using Python slicing The first approach is by using the Python slicing, It is the most common way to extract the substrings. Simply, we require the start and end indices. Example In the following example, ... Read More

31K+ Views
In this article, we are going to find out how to check if the type of a variable is a string in Python. It is necessary to verify the type of a variable before performing the operations. For example, if we want to ensure that the variable is a string before using the string methods like upper(), lower(). If the variable is not of the expected type, calling these methods will raise an error. Python provides various ways to check if the variable is of type string. Let's dive into the article to learn more about it. ... Read More

11K+ Views
While working with the texts in Python, we will find the strings that contain a mix of characters such as letters, digits, and white-space. In some scenarios, we may need to extract only the numeric digits from such strings. For achieving this, Python provides various ways. Let's explore one by one - Using Python str.isdigit() Method The first approach is by using the Python isdigit() method. It is used to check whether the character is a digit. It returns true if all the characters in the input string are digits. Syntax Following is the syntax for Python str.isdigit() ... Read More

2K+ Views
ASCII stands for the American Standard Code for Information Interchange. It represents the characters using the integer value from 0 to 127. In this article, we are going to explore the different ways to check if a string contains only ASCII characters in Python. It is necessary to verify whether a string contains only ASCII characters when ensuring compatibility. Using Python isascii() Method The Python isascii() method is a built-in method in Python 3.7. It returns true if all the characters in the string are ASCII; otherwise false. Syntax Following is the syntax for the Python isascii() method - ... Read More

976 Views
Here are some examples of how to delete a character from a string using Python. Using String Slicing One of the easiest ways to delete a character from a string in Python is to use string slicing. Here's how you can do it: Example In the first line of code, we define a string called "my_string" that contains the text "Hello World". In the second line of code, we remove the character "o" by creating a new string called "new_string". We do this by slicing the original string into two parts - the characters before the "o" and the ... Read More

990 Views
In this article, we are going to learn about converting a string to binary, which means representing each character in the string using the binary digits 0 and 1. A binary number is a number expressed in the base2 numerical system, which uses only two symbols - 0 and 1. Since computers store data as binary, converting the strings into binary helps to understand how data is stored or transmitted. Python provides several methods to achieve this. Using Python ord() and format() Functions The first approach is by using the Python ord() and format(), Where the Python ord() ... Read More

9K+ Views
To find all possible permutations of a given string, you can use the itertools module which has a useful method called permutations(iterable[, r]). This method return successive r length permutations of elements in the iterable as tuples. In order to get all the permutations as string, you'll need to iterate over the function call and join the tuples. For example: >>>from itertools import permutations >>>print [''.join(p) for p in permutations('dune')] ['dune', 'duen', 'dnue', 'dneu', 'deun', 'denu', 'udne', 'uden', 'unde', 'uned', 'uedn', 'uend', 'ndue', 'ndeu', 'nude', 'nued', 'nedu', 'neud', 'edun', 'ednu', 'eudn', 'eund', 'endu', 'enud'] If you don't want to use in built method, ... Read More

2K+ Views
In Python, the encoding() and decoding() refer to the processes of converting data between different formats, particularly when dealing with strings and bytes. Both processes are essential for ensuring data is correctly formatted for storage and transmission, especially when working with different languages or systems that may interpret data differently. Encoding in Python Encoding is the process of converting a string (text) into a byte sequence. This is often necessary when you need to store or transmit data as binary. When you want to save text to a file in a certain character encoding (e.g., UTF-8, ASCII) or send text ... Read More

18K+ Views
In this article, we are going to find out how to split a string on whitespace in Python. The first approach is by using the inbuilt method split(). This method splits the given string at our desired delimiter. The split() method accepts a parameter named as a delimiter, it specifies at what character should a string be split. So, we have to send white space as a delimiter to the split() method. This method returns the modified list that is split in white space. Example In the example given below, we are taking a string as input and we are ... Read More

9K+ Views
You can use regexes to remove the ANSI escape sequences from a string in Python. Simply substitute the escape sequences with an empty string using re.sub(). The regex you can use for removing ANSI escape sequences is: '(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]'.For example, import re def escape_ansi(line): ansi_escape =re.compile(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]') return ansi_escape.sub('', line) print escape_ansi(line = '\t\u001b[0;35mSomeText\u001b[0m\u001b[0;36m172.18.0.2\u001b[0m') This will give the output: '\tSomeText 172.18.0.2'Read More