
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 33676 Articles for Programming

1K+ 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

1K+ 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

737 Views
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

9K+ Views
In Python, the backslash-escaped string contains the characters that are followed by backslash(\), which are used as escape characters. For example, represents the literal characters "" and "n" (not a new line). In some scenarios, we need to unescape such a string, i.e, convert these sequences back to their intended special characters or read them as normal text. Python provides several ways to achieve this. In this article, we will explore how to un-escape a backslash-escaped string. Using Python .decode() Method The Python decode() method is used to decode the string using the codec ... Read More

8K+ Views
Concatenation is nothing but the process of joining two or more strings together. In Python, if one value is a number (integer or float), we can't directly concatenate it with a string using the '+' operator, as it raises a TypeError. Python does not allow the implicit conversion between strings and numbers during the concatenation. So, we need to explicitly convert the numbers to a string. Using Python str() Function The Python str() function is used to convert the given value into a string. In this approach, we are going to apply the str() function to ... Read More

6K+ Views
In Python formatting a floating point number to a fixed width can be done by using methods like Python's f-strings and the flexible format() method. Float formatting methods The two built-in float formatting methods are as follows f-strings: Convenient way to set decimal places, spacing and separators. str.format(): This method allows to formatting types inside the placeholders to control how the values are displayed. ... Read More