I mean hour and minutes. Taking them as arguments to input() function and assigning it to a variable. Is it possible?
Like this way:
time = input(current time)
I mean hour and minutes. Taking them as arguments to input() function and assigning it to a variable. Is it possible?
Like this way:
time = input(current time)
In case you need hour and minutes separately
from datetime import datetime
a=datetime.now()
print(a.hour,a.minute)
intput
only returns objects of type str
(string).
However, you can be inventive by specifying a certain format and performing the conversion using datetime
from the standard library:
from datetime import time
time = input('Enter a time in the format HH:MM \n')
# input 15:25
h, m = map(int, time.split(':'))
res = time(hour=h, minute=m)
print(res)
15:25:00