Found 33676 Articles for Programming

string.octdigits in Python

Hafeezul Kareem
Updated on 11-Jul-2020 07:52:45

165 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 Live Demo# 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 Live Demo# importing the string module import string # printing the octal digits string print(type(string.octdigits))OutputIf you run the above code, ... Read More

String slicing in Python to check if a can become empty by recursive deletion

Hafeezul Kareem
Updated on 11-Jul-2020 07:50:47

378 Views

In this tutorial, we are going to write a program that will check whether the given string can become empty or not by recursive deletion of chars using slice. Let's see an example to understand it more clearly.Inputstring = "tutorialstutorialspointpoint" sub_string = "tutorialspoint"OutputTrueAfter first iteration tutorialstutorialspointpoint becomes tutorialspoint.After the second iteration, the string will be empty.We can achieve the result using find() method of the string. Follow the below steps to write the program.Initialize the string and sub_string.If any of them is empty, then return FalseWhile string length is greater than zero. Do the following.Check whether the sub_string is present ... Read More

SQL using Python

Hafeezul Kareem
Updated on 11-Jul-2020 07:01:04

890 Views

In this tutorial, we are going to learn how to use SQL with Python using SQLite database. has a built-in module to connect with SQLite database. We are going to use sqlite3 module to connect Python and SQLite.We have to follow the below steps to connect the SQLite database with Python. Have a look at the steps and write the program.Import the sqlite3 module.Create a connection using the sqlite3.connect(db_name) the method that takes a database name is an argument. It creates one file if doesn't exist with the given name else it opens the file with the given name.Get the ... Read More

Split a string in equal parts (grouper in Python)

Hafeezul Kareem
Updated on 11-Jul-2020 06:59:37

367 Views

In this tutorial, we are going to write a program that splits the given string into equal parts. Let's see an example.Inputstring = 'Tutorialspoint' each_part_length = 5OutputTutor ialsp ointXInputstring = 'Tutorialspoint' each_part_length = 6OutputTutori alspoi ntXXXX We are going to use the zip_longest method from the itertools module to achieve the result.The method zip_longest takes iterators as argument. We can also pass the fillvalue for partitioning the string. It will return list of tuples that contains characters of equal number.The zip_longest return a tuple on each iteration until the longest iterator in the given in exhausted. And the tuple contains ... Read More

Sorted() function in Python

Hafeezul Kareem
Updated on 11-Jul-2020 06:58:18

421 Views

In this tutorial, we are going to learn about the sorted() function in Python.The function sorted() is used to sort an iterable in ascending or descending order. We can even sort the list of dictionaries based on different keys and values. Let's get most out of the sorted() function.The sorted() function is not an in-place algorithm like sort method.Default sorted()The function sorted() will sort an iterable in ascending order by default. Let's see an example.Example Live Demo# initializing a list numbers = [4, 3, 5, 1, 2] # sorting the numbers sorted_numbers = sorted(numbers) # printing the sorted_numbers print(sorted_numbers)OutputIf you run ... Read More

sort() in Python

Hafeezul Kareem
Updated on 11-Jul-2020 06:57:44

368 Views

In this tutorial, we are going to learn about the sort method of a list. Let's dive into the tutorial. The method sort is used to sort any list in ascending or descending order. There are many cases of sort method with or without optional parameters.The method sort is an in-place method. It directly changes in the original listLet's see one by one.Default sort()The method sort without any optional parameters will sort the list in ascending order. Let's an example.Example Live Demo# initializing a list numbers = [4, 3, 5, 1, 2] # sorting the numbers numbers.sort() # printing the numbers ... Read More

Set update() in Python to do union of n arrays

Hafeezul Kareem
Updated on 11-Jul-2020 06:55:48

332 Views

In this tutorial, we are going to write a program that uses set update method to union multiple arrays. And it will return a resultant one-dimension array with all unique values from the arrays.Let's see an example to understand it more clearly.Let's see an example to understand it more clearly.Inputarrays = [[1, 2, 3, 4, 5], [6, 7, 8, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]Output[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]Follow the below steps to write the program.Initialize the array as shown in the example.3Create an empty.Iterate over ... Read More

set copy() in python

Hafeezul Kareem
Updated on 11-Jul-2020 06:54:53

280 Views

In this tutorial, we are going to learn about the copy method set data structure. Let's see it in detail.The method copy is used to get a shallow copy of a set.Let's see different examples to under normal and shallow copy of a set.Normal CopyFollow the below steps and understand the output.Initialize a set.Assign the set to another variable with the assignment operator.Now, add one more element to the copied set.Print both sets.You won't find any difference between. The assignment operator returns the set reference. both sets are pointing to the same object in the memory. So, whatever changes made ... Read More

set clear() in python

Hafeezul Kareem
Updated on 11-Jul-2020 06:53:42

3K+ Views

In this tutorial, we are going to learn about the clear method of set data structure. Let's see details about the clear method.The method clear is used to clear all the data from the set data structure. All elements from set will clear. And we will leave with an empty set.Follow the below steps to see clear method in action.Initialize a set.User the clear method and clear the set.Print the set and you will see an empty one.Example Live Demo# initialzing a set number_set = {1, 2, 3, 4, 5} # clearing the set number_set.clear() # printing the set print(number_set)OutputIf you ... Read More

set add() in python

Hafeezul Kareem
Updated on 11-Jul-2020 06:51:05

250 Views

In this tutorial, we are going to learn about the add method of set data structure. Let's dive into the tutorial.Set data structure stores unique elements in it. The add method of set data structure takes an element and adds it to the set.Follow the below steps to add a new element to the set.Initialize a set.Add a new element to the set using the add method.Print the updated set.Example Live Demo# initialzing the set numbers_set = {1, 2, 3, 4, 4, 5} # adding an element to the set numbers_set.add(6) # printing the updated set print(numbers_set)OutputIf you run the above ... Read More

Advertisements