Programming Articles - Page 3270 of 3366

How to get formatted date and time in Python?

Nikitasha Shrivastava
Updated on 16-May-2025 17:49:47

112K+ Views

This article will discuss how to format date and time in Python. Python makes it easy to work with date and time with the help of the datetime module. You can format dates and times in different formats as per your needs. Datetime Module of Python The datetime module in Python offers methods for working with date and time values. To use this module, we must first import it using the following import keyword- import datetime Strftime() Function The strftime() function returns a formatted date and time. It accepts a format string that you can use to get the ... Read More

How to get current date and time in Python?

Nikitasha Shrivastava
Updated on 11-Jun-2025 14:38:02

1K+ Views

In this article, we will show you how you can get the current time and date in Python with the help of different functions. Here are the different ways to get the current Date and Time using the Datetime Module - Using the now() Method Using the today() Method Current ... Read More

How to print complete TimeTuple in Python?

Nikitasha Shrivastava
Updated on 06-Jun-2025 16:33:59

245 Views

In this article we will show you how you can print complete TimeTuple in Python. So printing a complete timeTuple in Python is very useful when you want to extract various parts of a date. For example you can use it to get the year, month, day, hour, minute, second and microsecond from a date. The time tuple is a tuple of 9 integers like year, month, day, hour, minute, second and microsecond. The first 6 items are required and the last 3 are optional basically. Here are different ways to do this task and print a time tuple - ... Read More

How to get timer ticks at a given time in Python?

Nikitasha Shrivastava
Updated on 11-Jun-2025 14:26:35

2K+ Views

In this article, we will show you how you can get the timer ticks at the given time using different functions in Python. To get the timer ticks at the given time, there is a time module available in Python. Here is the list of ways to solve this problem - Using time.time() Function Using time.perf_counter() Function Using time.process_time() Function Let us discuss each of these methods one by one in the section below - Using time.time() Function The time.time() function is used to get the current time in seconds. It returns the number of seconds since the ... Read More

What is a Tick in python?

Nikitasha Shrivastava
Updated on 06-Jun-2025 16:31:07

2K+ Views

In Python, a tick is the floating-point number to show time in seconds since January 1, 1970. This is mainly used in time calculations and logging timestamps in programs. Python's time module givens the function time.time() to fetch the current tick value. It is very useful for measuring execution tracks time in seconds. Also it helps in scheduling tasks with timestamps. Using Tick in Python The time.time() function from the time module gets the current tick value. This value increases as time moves forward. This method does not accept any parameters, as it always returns the current UTC time. ... Read More

How to get a list of all the values from a Python dictionary?

Nikitasha Shrivastava
Updated on 11-Jun-2025 13:55:46

24K+ Views

In this article, we will discuss how to extract a list of all the values from a Python dictionary. Following are various ways to retrieve list of all the values from a Python dictionary - Using dict.values() & list() Functions Using [] and * Using List comprehension ... Read More

How to get a list of all the keys from a Python dictionary?

Nikitasha Shrivastava
Updated on 11-Jun-2025 13:10:37

51K+ Views

In this article, we will show you how to get a list of all the keys from a Python dictionary. We can get the list of all the keys from a Python dictionary using the following methods - Using dict.keys() Method Using list() & dict.keys() Function Using List Comprehension ... Read More

How to get a value for a given key from a Python dictionary?

Nikitasha Shrivastava
Updated on 11-Jun-2025 12:47:53

34K+ Views

In this article, we will show you how to get a value for the given key from a dictionary in Python. Below are the 4 different methods to accomplish this task - Using Dictionary Indexing Using dict.get() Method Using keys() Function Using items() Function Assume we have taken a dictionary containing key-value pairs. We will return the value for a given key from a given input dictionary. Using dictionary indexing In Python, we can retrieve the value from a dictionary by using dict[key]. Example 1 The following program returns the index of the value for a given key ... Read More

How to convert a list into a tuple in Python?

Nikitasha Shrivastava
Updated on 16-Jun-2025 15:01:33

27K+ Views

List and Tuple in Python are classes of data structures. The list is dynamic, whereas the tuple has static characteristics. In this article, we will convert a list into a tuple by using a few methods. Each of these methods is discussed below. Converting List into Tuple using tuple() We can convert a list into a tuple using the tuple() function. This function accepts a list as a parameter, converts into a tuple and returns the result.Example 1 In the following program, we convert a list to a tuple using the tuple() function. # using tuple() built-in function list_names=['Meredith', 'Kristen', 'Wright', ... Read More

How does the del operator work on a tuple in Python?

Nikitasha Shrivastava
Updated on 11-Jun-2025 10:52:32

6K+ Views

A tuple is an ordered and immutable collection of Python objects separated by commas. Like lists, tuples are sequences. Tuples differ from lists in that they can not be modified, whereas lists can, and they use parentheses instead of square brackets. Though we can not change individual elements of a tuple, the del operator works with them. In this article, we are going to discuss the use of the del operator on a tuple. The del Operator with Tuples The del operator in Python is used to delete variables from the current scope. When you use "del" on a tuple ... Read More

Advertisements