Found 31499 Articles for Programming

How to Determine Last Friday’s Date using Python?

Vikram Chiluka
Updated on 24-Jan-2023 19:12:10
In this article, we will learn how to determine last Friday’s Date using Python. Methods Used The following are the various methods to accomplish this task − Using datetime module Using dateutil package Method 1: Using Datetime Module Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task. − Use the import keyword to import the datetime, timedelta from datetime module. Create a variable to store the list of all the days in a week(weekdays). Create a function getPreviousByDay() to return the last weekday of the input day by accepting the input day, ... Read More

How to detect whether a Python variable is a function?

Vikram Chiluka
Updated on 24-Jan-2023 19:10:46
In this article, we will learn how to detect whether a Python variable is a function. Sometimes, it is essential to figure out whether or not a Python variable is a function. When the code is a thousand lines long and you are not the creator of the code, this may appear to be of little value, and you may find yourself questioning if a variable is a function or not. Methods Used The following are the methods to check whether a python variable is a function − Using the built-in callable() function Using the isfunction() of the ... Read More

How to create a dictionary of sets in Python?

Vikram Chiluka
Updated on 24-Jan-2023 19:08:33
In this article, we will learn how to create a dictionary of sets in Python. Methods Used The following are the various methods used to accomplish this task − Using the Naive Method Using defaultdict() Method Using setdefault() Method Method 1: Using the Naive Method In this method, we create a dictionary of sets by passing sets as values to the keys. Syntax { ‘Key’: Set 1, ‘Key’:Set 2, ………….., ’Key’: Set n} Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Create a variable to store the dictionary containing ... Read More

How to capture SIGINT in Python?

Vikram Chiluka
Updated on 24-Jan-2023 20:10:44
In this article, we will learn how to capture SIGINT in Python and what has to be done after capturing it. When the signal module receives signals, it does a certain action. Besides that, it can capture the user's interruption through the keyboard using SIGINT. Modules Needed Signal Module The term "signal" refers to the process by which a program can receive information from the operating system. Additionally, the signals are sent to the program when the operating system detects specific events. By executing the following command at the terminal, the signal module can be installed − pip install signal ... Read More

How to Align Text Strings using Python?

Vikram Chiluka
Updated on 24-Jan-2023 19:02:30
In this article, we will learn how to align text strings using Python. We will be using f-strings for this aligning text strings in python. Python's Text Alignment feature is helpful for printing output that is well and cleanly formatted. Sometimes the length of the data to be printed varies, making it appear untidy when printed. By specifying the alignment as left, right, or center and the space (width) to reserve for the string, the output string can be aligned using String Alignment. The text will be formatted using the f-strings. The output string's alignment is defined by the symbols ... Read More

Finding unique elements from Tuple in Python

Vikram Chiluka
Updated on 24-Jan-2023 09:28:50
In this article, we will learn a Python program to find unique elements from a tuple. Methods Used The following are the various methods to accomplish this task − Using for loop and append() function Using collections.Counter() function Using set() function Tuples are an immutable, unordered data type used to store collections in Python. It can store multiple values in it. Lists and tuples are similar in many ways, but a list has a variable length and is mutable in comparison to a tuple which has a fixed length and is immutable. Method 1: Using for loop and ... Read More

Golang program to get maximum and minimum from a slice

Akhil Sharma
Updated on 23-Jan-2023 15:00:51
In this article, we will see how to fetch maximum and minimum elements from a slice. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover; they are passed by reference instead by value. Let us understand this basic concept using different set of examples and algorithms based upon them. Method 1: Using the Helper Function In this method, we will learn how to get ... Read More

Golang to check if a slice is empty

Akhil Sharma
Updated on 23-Jan-2023 14:58:50
In this article, we will check if the slice is empty or not using a variety of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s learn through examples how it can be executed. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. ... Read More

Golang program to check if two slices are equal

Akhil Sharma
Updated on 23-Jan-2023 14:55:05
In this article, we will see what are the ways to check whether two slices are equal or not with the help of relevant examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover; they are passed by reference instead by value. Let us learn the concept through examples. Method 1: Using a built-in Function In this method, we will use reflect.DeepEqual() function from ... Read More

Golang program to count the elements of a slice

Akhil Sharma
Updated on 23-Jan-2023 14:52:16
In this article, we will learn how to count the elements of a slice using a different set of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas a slice is a dynamic array, meaning its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover; they are passed by reference instead by value. Let us learn through examples how it can be executed. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to ... Read More
Advertisements