- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 27104 Articles for Server Side Programming
1K+ Views
Here, we are considering some code examples to remove specific characters from a string in Python: Using str.replace() In this method, we will use the str.replace() method to replace the specific characters with an empty string. Example We define a string called my_string that contains the original string we want to modify. We use the str.replace() method to replace all occurrences of the character 'o' with an empty string, effectively removing them from the string. We store the resulting string in a new variable called result. We print the resulting string. # define the string my_string = "Lorem Ipsum!" # ... Read More
5K+ Views
There are several ways to extract numbers from a string in Python. One way to extract numbers from a string is to use regular expressions. Regular expressions are patterns that you can use to match and manipulate strings. Here's an example code snippet that uses regular expressions to extract all the numbers from a string: Using the re.findall() function Example In this example, we're using the re.findall() function to search for all occurrences of numbers in the text string. The regular expression \d+\.\d+|\d+ matches both floating-point numbers and integers. import re text = "The price of the book is $29.99" ... Read More
354 Views
In Python, a substring is a sequence of characters that appears within a larger string. For example, in the string "Hello, world!", the substring "world" appears within the larger string. A substring can be a single character, or it can be a longer sequence of characters. Substrings are useful when you need to extract or manipulate specific parts of a string. You can also check if a substring is contained within a larger string using Python's string methods. Python provides a built-in method to check if a string contains a substring. The method is called ‘in’ and it returns a ... Read More
376 Views
To convert byte literals to Python strings, you need to decode the bytes. It can be done using the decode method on the bytes object. example>>> b"abcde".decode("utf-8") u'abcde'You can also map bytes to chr if the bytes represent ASCII encoding as follows −bytes = [112, 52, 52] print("".join(map(chr, bytes)))Outputp44
10K+ Views
A string is a collection of characters that can represent a single word or a complete phrase. Since you can directly assign strings in Python to a literal (unlike other technologies) it is easy to use them. Python includes a number of built in functions and methods to perform various operations on strings, a string is an object of the String class, which contains these methods. In this article, we are going to find out what is the b character that is present in front of a string literal does in python. The b literal in front of the string ... Read More
174 Views
To parse a string to int, you can use the following:try: print int('112') except ValueError: print 'Cannot parse'This will give you the output:112To parse a string to float, you can use the following:try: print float('112.15') except ValueError: print 'Cannot parse'This will give you the output:112.15
867 Views
Stripping down all the punctuation from a string in Python can be achieved using various methods. Here are some examples: Using string.punctuation Example The string.punctuation constant contains all the ASCII punctuation characters. We can use this constant to remove all the punctuation characters from the string. We are using a list comprehension to iterate over each character in the string and check if it's not in the string.punctuation constant. If it's not a punctuation character, we add it to the no_punct variable. import string # sample string with punctuation text = "Lorem, Ipsum!!!" # remove punctuation no_punct = "".join(char for ... Read More
4K+ Views
A string is a group of characters that may be used to represent a single word or an entire sentence. Strings are simple to use in Python since they do not require explicit declaration and may be defined with or without a specifier. In Python strings are represented by the class named string and this class provides several built-in methods to manipulate and access strings. In this article, we are focusing on how to check if a string contains only decimal characters in Python. Using the isdigit() function One way to achieve this is using the inbuilt string function isdigit(). ... Read More
3K+ Views
To get the POST values from serializeArray in PHP, use the serializeArray() method. The serializeArray( ) method serializes all forms and form elements like the .serialize() method but returns a JSON data structure for you to work with.Let’s say we have the PHP content in serialize.php file:ExampleThe following is an example showing the usage of this method:Live Demo The jQuery Example $(document).ready(function() { $("#driver").click(function(event){ ... Read More
16K+ Views
A string is a group of characters that can represent a single word or a whole sentence. In Python there is no need to declare strings explicitly we can directly assign them to a literal. Therefore, easy to use them. A string is an object of the String class, which has multiple methods to manipulate and access strings. In this article, we are going to find out how to get a string left padded with zeros in Python. Using the rjust() function One way to achieve this is using the built-in string function named rjust(). The width argument is the ... Read More