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

2K+ Views
A bytestring in Python is a sequence of bytes, represented using the bytes data type in Python 3. Bytestrings are primarily used to handle binary data or data that doesn't conform to the ASCII or Unicode encodings, such as images, audio files, and more. They are crucial for tasks that require low-level data manipulation. Creating a Bytestring To create a bytestring in Python, prefix a string literal with the letter b. This indicates to Python that the string should be interpreted as a sequence of bytes. Example In this example, we create a bytestring with the contents "This is a ... Read More

833 Views
There are two ways to go about replacing \ with \ or unescaping backslash escaped strings in Python. First is using literal_eval to evaluate the string. Note that in this method you need to surround the string in another layer of quotes. For example:>>> import ast >>> a = '"Hello,world"' >>> print ast.literal_eval(a) Hello, worldAnother way is to use the decode('string_escape') method from the string class. For example,>>> print "Hello,world".decode('string_escape') Hello, world

3K+ Views
Sorting the string that contains the number, such as ("xy1", "xy2", "xy10"), can be complex in Python. For example, if we sort the list ["xy1", "xy2", "xy10"] using the built-in sort() method, it results in ["xy1", "xy10", "xy2"]. But we will expect "xy2" to come before "xy10". It is because the Python default sorting uses the lexicographical order and compares the characters from left to right based on their Unicode values. Since the character '1' in "xy10" comes before "2" in "xy2", the "xy10" is treated as smaller, even though the number 10 is greater than 2. This ... Read More

7K+ Views
In this article, we are going to learn how to replace the last occurrence of an expression in a string. In Python, String manipulation is a common task, and Python provides the built-in method named replace(). Though we can replace the specified character or substring in a string using this method, it does not directly support replacing the last occurrence. To achieve this we need to use slicing or a regular expression. Using Python rfind() Method The first approach is by using the Python rfind() method searches for the starting index of the last occurrence of the specified substring. Here, we ... Read More

15K+ Views
A string is a collection of characters that can represent a single word or a whole sentence. Unlike Java, there is no need to declare Python strings explicitly; we can directly assign a string value to a literal. While working with the string, we will encounter situations to check whether the string starts with a capital letter. This can be useful for validating the names or sentences to ensure they follow certain formatting rules. Python provides multiple methods to test this condition. In this article, we will explore how to test if a string with a capital letter. ... Read More

445 Views
A string is a collection of characters stored as a single value. Un like other technologies there is no need to explicitly declare strings in python (for that matter any variable), you just need to assign strings to a literal this makes Python strings easy to use. In Python, a string is represented by the class named String. This class provides several functions and methods using which you can perform various operations on strings. In this article, we are going to find out how to check whether a string starts with XYZ in Python. Using startswith() method One way to ... Read More

23K+ Views
In Python, we will come across situations where we encounter long lines of code that exceed the recommended line length of 79 characters (suggested by the Python style guide). To improve code readability, Python provides several ways to wrap long lines. In this article, we will explore the various methods to wrap long lines in Python. Using Backslash(\) The Backslash(\) is used as the line continuation character in Python. It indicates the compiler that the statement continues on the next line. If we try to place anything (word, space or comment) after the backslash, it will result in ... Read More

9K+ Views
In Python 3, the input() function always returns a string, even if the user enters a number. To check if the user input is an integer, you can use a try-except block and attempt to convert the input string to an integer using the int() function. Here are some code examples that demonstrate different ways to check if raw input is an integer in Python 3: Using a try-except block Example In this example, we use a try-except block to attempt to convert the user's input to an integer using the int() function. If the user enters an integer, the ... Read More

269 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.