Gistlib Logo

gistlib

create function that takes three numbers as parameters and returns a string with the numbers formatted as "hh-mm-ss" in python

main.py
def format_time(hours, minutes, seconds):
    return f"{hours:02d}-{minutes:02d}-{seconds:02d}"
96 chars
3 lines

In this function, we use string formatting with f-strings and the :02d format code to ensure that each number is zero-padded and has two digits.

similar python code snippets

take first name and last name, create email address in the format firstname.lastname@fhws.de in python
print at specific location on the screen in python
zero pad in python
if length of string is 1 add 0 to the beginninh in python
datetime to string in python
create a function that multiple 40 times hello world and add 20 times the holoworld in a string in python
format a date in to the format 'yyyy-mm-dd hh:mm:ss.fff' in python
generate a password of 8 characters that contains at least one uppercase letter, one lowercase letter, and one number in python
find email addresses in a string using regex in python
find urls in a string in python

related categories

python
function
parameters
string formatting
date/time

gistlibby LogSnag