Pranav Indukuri

Pranav Indukuri

18 Articles Published

Articles by Pranav Indukuri

18 articles

How do I calculate number of days between two dates using Python?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 34K+ Views

In this article we will discuss how to find the number of days between two dates using Python. We use the datetime module to calculate the difference between dates, which returns a timedelta object containing the number of days. Using datetime.date() Python's built-in datetime module provides the date class for handling dates. To find the difference between two dates, we create date objects and subtract them ? Syntax datetime.date(year, month, day) Parameters year − Integer representing the year (MINYEAR ≤ year ≤ MAXYEAR) month − Integer representing the month (1 ≤ ...

Read More

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

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 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 ...

Read More

How to convert Python DateTime string into integer milliseconds?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 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 ...

Read More

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

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 22K+ 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 microsecond. 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. We retrieve the current minutes, seconds, and milliseconds by using .minute, .second, ...

Read More

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

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 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 The mktime() method from the Python time module is the inverse function of the localtime(). This method converts a time.struct_time object or a tuple with 9 ...

Read More

How to convert date to datetime in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 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 several ways to achieve this ? Syntax The syntax of the combine() method is as follows ? datetime.combine(date, time) Using combine() with ...

Read More

How do make a flat list out of list of lists in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 589 Views

A nested list is a list that contains other lists as elements. For example: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] is a nested list with 3 sublists as its elements. To flatten a list of lists (convert a 2D list into a 1D list), Python offers several approaches: nested for loops, list comprehension, built-in functions like itertools.chain(), or using libraries like NumPy. In this article, we will explore these methods to flatten a list in Python. Using Nested For Loops The most straightforward approach is to iterate through each sublist and add its ...

Read More

How do we assign a value to several variables simultaneously in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 7K+ Views

Python is not a "statically typed" programming language. We do not need to define variables or their types before utilizing them. Once we initially assign a value to a variable, it is said to be created. Each variable is assigned with a memory location. The assignment operator (=) assigns the value provided to right to the variable name which is at its left. The syntax of the assignment operator is shown below − var_name = value Example of Assignment Operator The following is an example that shows the usage of the assignment operator − ...

Read More

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

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 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 while loop to continuously prompt the user for input and append elements to the list. When we do not enter any element into the list and just ...

Read More

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

Pranav Indukuri
Pranav Indukuri
Updated on 24-Mar-2026 799 Views

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

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