Found 33676 Articles for Programming

How to check if a string contains only decimal characters?

Yaswanth Varma
Updated on 14-Apr-2025 11:46:15

5K+ Views

In many programming scenarios, it is common to validate the user input to ensure it contains the specified value. For example, when accepting age, pin-code or numbers form the user, we make sure the input is entered is completely digits. One specific way to do this is by checking if the string contains only decimal numbers. Decimal characters are the characters used to write base-10 numbers (the digits from 0-9). Python provides the built-in methods to perform this check easily, Let's dive into the article to learn more about it. Using Python isdecimal() Method The Python isdecimal() ... Read More

How to get the POST values from serializeArray in PHP?

Ricky Barnes
Updated on 20-Dec-2019 06:20:34

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

How to get a string left padded with zeros in Python?

Tarun Chandra
Updated on 19-Oct-2022 12:10:52

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

How to translate a python string according a given dictionary?

Yaswanth Varma
Updated on 14-Apr-2025 11:43:53

2K+ Views

In Python, translating the string using a dictionary is used for text manipulation, encoding. It is typically achieved by using the str.translate() method along with the str.maketrans() to define the character mappings. The dictionary passed to the maketrans() contains key-value pairs where the keys are characters to replace and values are their corresponding replacements. Let's dive into the article to learn more about translating a string using the dictionary. Using Python str.translate() Method The Python str.translate() method is a sequel for the maketrans() method in the string module. This method uses the translation table generated by the ... Read More

How to Convert Lowercase Letters in String to Uppercase in Python?

Yaswanth Varma
Updated on 14-Apr-2025 11:30:55

4K+ Views

Converting the lowercase letters in a string to uppercase is a common task in Python. When working with the user input or formatting output, Python provides efficient ways to handle the letter casing. The most commonly used method is the built-in string method upper(). We can use loops and list comprehensions with this method, if we need to convert individual tokens of a string to upper case. Using python upper() Method The Python upper() method is used to convert all the lowercase characters present in a string into uppercase. However, if there are elements in the string that are already ... Read More

How to invert case for all letters in a string in Python?

Tarun Chandra
Updated on 19-Oct-2022 12:02:47

3K+ Views

A string is a group of characters that can represent a single word or a complete sentence. In Python there is no need to declare variables explicitly using the datatype specifier you can directly assign them to a literal. Therefore, compared to other technologies like Java it is easy to use Python strings. For manipulating and accessing strings, Python includes several built in functions and methods. You can find these functions in a class named String. In this article, we are going to focus on how to invert the case for all letters in a string in Python. Using the ... Read More

Handling Exception and use of CX_ROOT directly and subclasses

Sai Nath
Updated on 14-Feb-2020 05:37:06

356 Views

It is not advisable to use CX_ROOT directly and you would require using one of its direct subclasses. Also, the propagation depends upon the exception subclass hierarchy.Subclasses of CX_STATIC_CHECK – these do not propagate automatically. You will need to do the handling yourself or there will be a syntax error in the program.Subclasses of CX_DYNAMIC_CHECK – these do not require any handling. But the program that does not handle the exception will be aborted with these subclasses.Subclasses of CX_NO_CHECK – These will get propagated automatically if the exception is not handled.

How to check if string or a substring of string starts with substring in Python?

Yaswanth Varma
Updated on 11-Apr-2025 12:04:01

1K+ Views

In this article we are going to check whether the string starts with the substring or not, It is useful for checking whether the string starts with the substring, which is helpful in tasks like filtering data or validating input. In Python there are various ways to perform this check, such as startswith(), string slicing and regular expression. Let's dive into the article to learn more about them. Using python startswith() Method The Python startswith() method is used to check whether the string starts with a given substring or not. This method accepts a prefix string that you ... Read More

How to split at NEWLINEs in Python?

Tarun Chandra
Updated on 07-Dec-2022 07:31:08

32K+ Views

In this article, we are going to find out how to split at newlines in Python. In general, split means to divide or to make a group of objects divide into smaller groups. The first approach to split at NEWLINES in python is by using the inbuilt method splitlines(). It takes a multi-line string as input and it returns a separated string that is divided at the new line. It doesn’t take any parameters. The splitlines() method is an inbuilt string method and it is used only for splitting at the new lines. Example 1 In the program given below, ... Read More

How to split string by a delimiter string in Python?

Yaswanth Varma
Updated on 11-Apr-2025 12:03:31

2K+ Views

While working with the strings in python, we will find the situations to break the string into parts. This is called splitting a string and is usually done based on a delimiter, this is nothing but a character or sequence of characters that separate the parts of the string. Python provides the several ways for achieving this, depending on whether the delimiter is simple string or a pattern. Let's dive into the article to learn more about splitting string by delimiter. Using python split() Method The python split() method is used to split the words in a string separated by ... Read More

Advertisements