-3

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)
Omar
  • 39
  • 2
  • 6
  • Possible duplicate of [How to get current time in Python?](https://stackoverflow.com/questions/415511/how-to-get-current-time-in-python) – BERA May 04 '18 at 09:22
  • 1
    Is your intention to get the current time or to put the time in the input display or to get the time when a user inputs a response or...? – TerryA May 04 '18 at 09:22
  • Possible duplicate of https://stackoverflow.com/questions/31387596/how-do-i-take-input-in-the-date-time-format – Const May 04 '18 at 09:23
  • Did an answer below help? Feel free to accept an answer (green tick on left), or ask for clarification. – jpp May 08 '18 at 11:08

2 Answers2

1

In case you need hour and minutes separately

from datetime import datetime
a=datetime.now()
print(a.hour,a.minute)
Rao Sahab
  • 1,161
  • 1
  • 10
  • 12
0

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
jpp
  • 159,742
  • 34
  • 281
  • 339