Pranav Indukuri

Pranav Indukuri

18 Articles Published

Articles by Pranav Indukuri

18 articles

How to convert date to datetime in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 28-Aug-2025 41K+ Views

In this article, we will discuss how to convert a date to a datetime object in Python. We use the combine() method from the Date & Time module to combine a date object and a time object into a single datetime object. While the date object represents only the calendar date (year, month, day), sometimes we need the full datetime object that includes time (hour, minute, second) as well. Following are the several ways to achieve this. The syntax of the combine() method is as follows. datetime.combine(date, time) Converting a date object to a datetime Object Using the combine() Method The ...

Read More

How to get min, seconds and milliseconds from datetime.now() in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 28-Aug-2025 21K+ Views

Python's datetime module is used to extract various components of the current date and time, such as minutes, seconds, and even milliseconds. The datetime.now() method defined in the datetime module returns the current local date and time as a datetime object. This object allows us to access its individual components like minute, second, and millisecond. Using Attributes of datetime.now() to Extract Values Here we use the datetime.now() method to get the current minutes, seconds, and milliseconds. The now() function is defined under the datetime module. And retrieve the current minutes, seconds, and milliseconds by using .minute, .second, and .microsecond, respectively. ...

Read More

How to convert Python date format to 10-digit date format for mysql?

Pranav Indukuri
Pranav Indukuri
Updated on 28-Aug-2025 2K+ Views

While working with databases like MySQL, it’s necessary to store dates in a numeric format, especially for timestamps. MySQL commonly uses Unix timestamps, which are 10-digit numbers representing the number of seconds since January 1, 1970 (known as the epoch). The following are the different methods from the time and datetime modules to convert Python date formats into a 10-digit format (Unix timestamp) suitable for use with MySQL. Using mktime() Method Using strptime() + mktime() Combination Using timestamp() Method Using mktime() Method The mktime() method from ...

Read More

How to convert time seconds to h:m:s format in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 28-Aug-2025 8K+ Views

In Python, while working on date and time, converting time seconds to h:m:s (Hours: Minutes: Seconds) format can be done using simple arithmetic operations and built-in modules like datetime and time. The following are several ways to convert time seconds to h:m:s format. Using arithmetic operations (Naive Method) Using the timedelta class of the datetime module Using time.strftime() with time.gmtime() Using arithmetic operations (Naive method) This is the simplest way to convert seconds into time in H:M:S format. We use basic mathematical operations like division and modulo ...

Read More

How to convert Python DateTime string into integer milliseconds?

Pranav Indukuri
Pranav Indukuri
Updated on 28-Aug-2025 7K+ Views

Python provides the time and datetime modules to convert a DateTime string into integer milliseconds. Key functions include time.time(), which gives the current time in seconds, and datetime.timestamp(), which converts datetime objects directly into seconds since the epoch. By multiplying these values by 1000, we can get the time in milliseconds. Using time.time() Method The time module in Python provides various methods and functions related to time. Here we use the time.time() method to get the current CPU time in seconds. The time is calculated since the epoch, which returns a floating-point number expressed in seconds. This value is multiplied ...

Read More

How to find what is the index of an element in a list in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Apr-2025 785 Views

In Python, an index is an element's location within an ordered list. Where n is the length of the list, and the first entry has a zero index, and the last element has an n-1 index. In this tutorial, we will look at how to find out the index of an element in a list in Python. There are different methods to retrieve the index of an element. Using index() method Three arguments can be passed to the list index() method in Python - element: element that has to be found. start ...

Read More

How do we assign values to variables in a list using a loop in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 23-Apr-2025 7K+ Views

In Python, lists are a useful way to store multiple elements in a single variable. To assign values to each entry in a list, loops are often needed. This strategy simplifies the process and improves the clarity of your code. This chapter will look at how to assign values to variables in a list using different loop types, using basic examples. Using Simple Loop Iterations In this method, we use the for loop to append elements to the lists. When we do not enter any element into the list and stop appending, then we just press the Enter key. To ...

Read More

How to match at the beginning of string in python using Regular Expression?

Pranav Indukuri
Pranav Indukuri
Updated on 23-Apr-2025 13K+ Views

A regular expression in Python is a group of characters that allows you to use a search pattern to find a string or set of strings. RegEx is a term for regular expressions. To work with regular expressions in Python, use the re package. Understanding String Matching in Python String matching is a basic Python method that allows you to look for and find patterns in a given text. The match() function, a component of the re (regular expression) package, is one of the widely used methods for this purpose. Use the match() method to determine whether the beginning of ...

Read More

How to match at the end of string in python using Regular Expression?\\n\\n

Pranav Indukuri
Pranav Indukuri
Updated on 23-Apr-2025 15K+ Views

A regular expression in Python is a set of characters that allows you to use a search pattern to find a string or a group of strings. These are used within Python using the re package. To match the end of the string in Python by using a regular expression, we use the following regular expression -^/w+$ Here, $ implies the start with. /w returns a match where ...

Read More

How to match any non-digit character in Python using Regular Expression?\\n\\n

Pranav Indukuri
Pranav Indukuri
Updated on 23-Apr-2025 7K+ Views

A regular expression is a group of characters that allows you to use a search pattern to find a string or a set of strings. RegEx is another name for regular expressions. The re module in Python is used to work with regular expressions. In this article, we learn how to extract non-digit characters in Python using regular expressions. We use \D+ regular expression in Python to get non-digit characters from a string. Where, \D returns a match that does not contain digits. + implies zero or more occurrences of characters. ...

Read More
Showing 1–10 of 18 articles
« Prev 1 2 Next »
Advertisements