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

我正在尝试返回当前时间,但由于某种原因我无法。我返回这个:

ZeroPadding1D

我的功能很简单

<function getHorarioactual at 0x000001E292E53950>
xihaibo 回答:在函数python中返回值时出现问题

您不需要所有这些变量来格式化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'
>>>
,

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

x = getHorarioActual

而不是

x = getHorarioActual()
,
import datetime

def getHorarioActual():
    now = datetime.datetime.now()

    horaActual = now.hour
    minutoActual = now.minute
    auxiliar = str(horaActual)+":"+str(minutoActual)
    horarioActual = auxiliar

    return horarioActual

t = getHorarioActual()
print(t)
本文链接:https://www.f2er.com/3114055.html

大家都在问