Found 10441 Articles for Python

How do we use Python regular expression to match a date string?

Nikitasha Shrivastava
Updated on 16-Jun-2025 12:32:16

7K+ Views

Regular expressions, or regex, are useful in Python when you need to find patterns in text. If you want to perform verification for a string that contains a date, in this case regex is useful. In this article, we will learn simple ways to match date strings using Python regex in the coming sections. Dates can come in many formats, like - YYYY-MM-DD YYYY/MM/DD YYYY.MM.DD YYYYMMDD DD-MM-YYYY DD/MM/YYYY Regular expression helps us find these patterns easily, so we can validate or extract dates from the given text. There are several ways to match a date string ... Read More

What is Raw String Notation in Python regular expression?

Nikitasha Shrivastava
Updated on 16-Jun-2025 12:27:36

6K+ Views

This article will discuss what raw string notation is in Python regular expressions. Regex is a set of characters that specifies a search pattern and is mostly used in text processors and search engines to execute find and replace operations.In Python,  regular expressions are used to find patterns in text. But some characters (like and \t) may create problems. Raw string notation (r'') can be useful here! This allows Python to treat backslashes as normal characters, which makes regex patterns easy to create and interpret. Python uses "" to escape characters in raw strings. This can change your regex pattern, ... Read More

How to get file creation & modification date/times in Python?

Nikitasha Shrivastava
Updated on 16-Jun-2025 12:17:24

15K+ Views

There are various ways to get the file creation and modification datetime in Python. We will use different methods from the OS and pathlib module to get the file creation and modification datetime in Python. Using OS Module: File Creation Time On Windows Using OS Module: File Modification Time On Windows ... Read More

How to convert a Python date string to a date object?

Nikitasha Shrivastava
Updated on 16-Jun-2025 12:02:41

9K+ Views

In this article, we convert a date string to a date object. We will use the strptime() method to convert a date string to a date object, and we will also use the dateutil module for flexible date parsing. A date string is a date written in text form, like "09 May 2025" or "2025-05-09". To work with dates in Python, we will have to convert these strings into date objects. To achieve this, we can use Python's datetime and dateutil modules. Using the strptime() Function The strptime() method takes the date as input and converts it into a ... Read More

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

203 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

Advertisements