函数python中返回值时出现问题

函数python中返回值时出现问题,python,datetime,Python,Datetime,我试图返回当前时间,但由于某些原因,我无法返回。我退回这个: <function getHorarioActual at 0x000001E292E53950> 您显然没有正确调用函数,正在编写 x = getHorarioActual x = getHorarioActual() 而不是 您不需要所有这些变量来格式化HH:MM中的时间。您的函数可以定义为: from datetime import datetime def getHorarioActual(): r

我试图返回当前时间,但由于某些原因,我无法返回。我退回这个:

<function getHorarioActual at 0x000001E292E53950>

您显然没有正确调用函数,正在编写

x = getHorarioActual
x = getHorarioActual()
而不是


您不需要所有这些变量来格式化
HH:MM
中的时间。您的函数可以定义为:

from datetime import datetime

def getHorarioActual():
    return datetime.now().strftime('%H:%M')
以下是概念证明:

Python 3.7.5 (default, Oct 17 2019, 12:16:48) 
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> def getHorarioActual():
...     return datetime.now().strftime('%H:%M')
... 
>>> getHorarioActual()
'19:05'
>>>

请包括对
getHorarioActual
的调用,因为您没有调用该函数。你也可以只返回表达式,auxiliar和对horarioActual的重新分配都是毫无意义的,你也不需要从头开始。只需使用
datetime.datetime.now().strftime(“%H:%M”)
。变量名应遵循
小写字母加下划线的惯例,而不是
camelCase
或其他任何形式。请查看更多信息。而且,这看起来不像是您的完整代码。你能和我共用一个房间吗?
from datetime import datetime

def getHorarioActual():
    return datetime.now().strftime('%H:%M')
Python 3.7.5 (default, Oct 17 2019, 12:16:48) 
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> def getHorarioActual():
...     return datetime.now().strftime('%H:%M')
... 
>>> getHorarioActual()
'19:05'
>>>