
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 10543 Articles for Python

265 Views
The string formatting operator ('%') in Python is used for string formatting, allowing you to embed variables or values directly into a string. It's often referred to as "printf-style" string formatting because it's similar to the sprintf() function in C. How it Works The % operator takes a format string on the left and a value (or tuple of values) on the right. The format string contains placeholders (like %s, %d, %f, etc.) that indicate where and how the values should be inserted into the string. Basic String Insertion (%s) The %s placeholder is used to insert strings into a string. ... Read More

4K+ Views
With a 64-bit Python installation, and 64 GB of memory, a Python 2 string of around 63 GB should be quite feasible. If you can upgrade your memory much beyond that, your maximum feasible strings should get proportionally longer. But this comes with a hit to the runtimes.With a typical 32-bit Python installation, of course, the total memory you can use in your application is limited to something like 2 or 3 GB (depending on OS and configuration), so the longest strings you can use will be much smaller than in 64-bit installations with very high amounts of RAM.

691 Views
You can use dictionaries to interpolate strings. They have a syntax in which you need to provide the key in the parentheses between the % and the conversion character. For example, if you have a float stored in a key 'cost' and want to format it as '$xxxx.xx', then you'll place '$%(cost).2f' at the place you want to display it.Here is an example of using string formatting in dictionaries to interpolate a string and format a number:>>>print('%(language)s has %(number)03d quote types.' % {'language': "Python", "number": 2}) Python has 002 quote types.You can read up more about string formatting and their ... Read More

7K+ Views
In Python, Sorting the string alphabetically is a common task helps for string manipulation or text analysis. It is used in creating the anagrams, checking for permutations, or standardizing the input for consistent processing, for example, turning 'banana' into 'aaabnn'. In this article, we will explore how to sort the letters in a string alphabetically, this can be done by using the Python built-in function. Using Python sorted() Function The Python sorted() function is used to return a new sorted list from the items in the iterable object. The order of sorting can be set to either ascending ... Read More

2K+ Views
In Python, a string is a sequence of Unicode characters, while a byte string is a sequence of raw bytes. Here are three examples that demonstrate the difference between a string and a byte string: Creating a String Example In this example, we define a string "Lorem Ipsum" using double quotes. This string is made up of Unicode characters that can be encoded in different ways. # Define a string my_string = "Lorem Ipsum" # Print the string print(my_string) Output Lorem Ipsum Creating a Byte String Example In this example, we define a byte string "Lorem Ipsum" using ... Read More

9K+ Views
Strings are one of the most commonly used data types. In this article, we are going to find out how to convert a string to a list of words in Python. Converting the string into a list is helpful when dealing with user inputs or when we want to manipulate individual words in a string. Python provides several ways to achieve this. Let's explore them one by one. Using Python str.split() Method Python str.split() method accepts a separator as a parameter, splits the string at the specified separator, and returns the result as a list. If we use the split() ... Read More

6K+ Views
A string is a collection of characters that may be used to represent a single word or an entire phrase. Strings are useful in Python since they don't need to be declared explicitly and may be defined with or without a specifier. In this article, we are going to find out how to split a multi-line string into multiple lines in Python. While working with the strings in programs, we will come across multi-line strings. To process such strings one by one, we need to split the string into individual lines. In this article, we will explore different methods. ... Read More

1K+ Views
In this article, we are going to find out how to remove a substring from the end of a string in Python. The first approach is by using slicing approach. In this method, we will check if the string is ending with the given substring or not, if it is ending with the given substring then we will slice the string, removing the substring. The ability to access portions of sequences like strings, tuples, and lists in Python is known as slicing. Additionally, you can use them to add, remove, or edit the elements of mutable sequences like lists. Slices ... Read More

1K+ Views
In this article, we are going to find out how can we tell if a string repeats itself in Python. The first approach is by using slicing and find(). We want to see if the string we have is made up entirely of repeats of a substring of the string. We can confirm this by looking for a rotation of the string in a pair of strings. After adding a string and checking the root string in this string, except for the last and first character, we may search for the root string. This approach doesn’t work for strings with ... Read More

2K+ Views
In this article, we are going to find out how to do string concatenation without the plus operator in Python. Generally, String concatenation is the process of joining two or more strings into one, and the common way to do this is by using the '+' operator. For example, writing "Welcome" + " " + "TP" results in the string "Welcome TP". But here we need to perform the concatenation without the '+' operator. For achieving this, Python provides alternative methods, which we will explore one by one. Using Python join() Method The first approach is ... Read More