Python Articles

Page 130 of 852

string.octdigits in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 214 Views

In this tutorial, we are going to learn about the string.octdigits string.The string octdigits is pre-defined in the string module of the Python3. We can use the octal digits whenever we want in the program by simply accessing it from the string module.Example# importing the string module import string # printing the octal digits string print(string.octdigits)OutputIf you run the above code, then you will get the following result.01234567The string.octdigits is a string. You can it by executing the following program.Example# importing the string module import string # printing the octal digits string print(type(string.octdigits))OutputIf you run the above code, then you ...

Read More

string.punctuation in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 4K+ Views

In this tutorial, we are going to learn about the string.punctuation string.The string punctuation is pre-defined in the string  module of Python3. It contains all the characters as a string. We can use it anywhere in the program.Example# importing the string module import string # printing the punctuation print(string.punctuation)OutputIf you run the above code, then you will get the following result.!"#$%&'()*+,-./:;?@[\]^_`{|}~ConclusionWe can use it to generate strong passwords. Try it out. If you have any doubts in the tutorial, mention them in the comment section.

Read More

string.whitespace in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 449 Views

In this tutorial, we are going to learn about the string.whitespace.The string whitespace is pre-defined in the string module of Python3. If contains space, tab, linefeed, return, formfeed, and vertical tab.Example# importing the string module import string # printing a string print("Hello") # whitespace printing print(string.whitespace) # printing a string print('tutorialspoint')OutputIf you run the above code, then you will get the following result.Hello tutorialspointConclusionIf you have any doubts in the tutorial, mention them in the comment section.

Read More

struct module in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 4K+ Views

In this tutorial, we are going to learn about the struct module. Let's dive into the tutorial.The module struct is used to convert the native data types of Python into string of bytes and vice versa. We don't have to install it. It's a built-in module available in Python3.The struct module is related to the C languages. We have to know the notations used in C to represent various data type to work with struct module. Let's see some of them.Data TypeFormat CharacterinticharcstringsfloatfLet's see how to convert the Python data types into bytes.struct.pack()The method struct.pack() is used to convert the ...

Read More

Sum of list (with string types) in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 3K+ Views

In this tutorial, we are going to write a program that adds all numbers from the list. List may contain numbers in string or integer format. See the example.Inputrandom_list = [1, '10', 'tutorialspoint', '2020', 'tutorialspoint@2020', 2020]Output4051Follow the below steps to write the program.Initialize the list.3Initialize a variable total with 0.Iterate over the list.If the element is int, then add it to the total by checking two conditions.The element will be int -> Check type.The element will be a number in string format -> Check using isdigit() method.Print the totalExample# initialzing the list random_list = [1, '10', 'tutorialspoint', '2020', 'tutorialspoint@2020', 2020] ...

Read More

Swap two variables in one line in C/C++, Python, PHP and Java

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 654 Views

In this tutorial, we are going to learn how to swap two variables in different languages. Swapping means interchanging the values of two variables. Let's see an example.Inputa = 3 b = 5Outputa = 5 b = 3Let's see one by one.PythonWe can swap the variable with one line of code in Python. Let's see the code.Example# initializing the variables a, b = 3, 5 # printing before swaping print("Before swapping:-", a, b) # swapping a, b = b, a # printing after swapping print("After swapping:-", a, b)OutputIf you run the above code, then you will get the following result.Before ...

Read More

The most occurring number in a string using Regex in python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 277 Views

In this tutorial, we are going to write a regex that finds the most occurring number in the string. We will check the regex in Python.Follow the below steps to write the program.Import the re and collections modules.Initialize the string with numbers.4Find all the numbers using regex and store them in the array.Find the most occurring number using Counter from collections module.Example# importing the modules import re import collections # initializing the string string = '1222tutorials321232point3442' # regex to find all the numbers regex = r'[0-9]' # getting all the numbers from the string numbers = re.findall(regex, string) # counter ...

Read More

time.perf_counter() function in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 4K+ Views

In this tutorial, we are going to learn about the time.perf_counter() method.The method time.perf_counter() returns a float value of time in seconds. Let's see anExample# importing the time module import time # printing the time print(time.perf_counter())OutputIf you run the above code, then you will get the following result.263.3530349We can use the time.perf_counter() method to find the execution time of a program. Let's see an example.Example# importing the time module import time # program to find the prime number def is_prime(number):    for i in range(2, number):       if number % i == 0:          return ...

Read More

Divide Array Into Increasing Sequences in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 286 Views

Suppose we have a non-decreasing array of positive integers called nums and an integer K, we have to find out if this array can be divided into one or more number of disjoint increasing subsequences of length at least K.So, if the input is like nums = [1, 2, 2, 3, 3, 4, 4], K = 3, then the output will be true, as this array can be divided into the two subsequences like [1, 2, 3, 4] and [2, 3, 4] with lengths at least 3 each.To solve this, we will follow these steps −d := a new mapreq ...

Read More

time.process_time() function in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 2K+ Views

In this tutorial, we are going to learn about the time.process_time() method.The method time.process_time() will return a float value of time in seconds of a system and user CPU time of the current process.Example# importing the time module import time # printing the current process time print(time.process_time()) 1.171875OutputIf you run the above code, then you will get the similar result as follows.1.171875Let's say we have a process that prints from in the given range. Let's find the time for that process. Understand the following code and run it.Example# importing the time module import time # program to find the prime ...

Read More
Showing 1291–1300 of 8,519 articles
« Prev 1 128 129 130 131 132 852 Next »
Advertisements