Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 创建函数时出现语法错误_Python - Fatal编程技术网

Python 创建函数时出现语法错误

Python 创建函数时出现语法错误,python,Python,我对python还比较陌生,正在研究它。我正在尝试创建一个函数来创建时间消息。我的代码中的单词“year”被突出显示,表明它是无效语法。代码目前还不完整,还有一些事情我需要修复,我现在有点不知所措 我试图解决的问题是: def timeMessage(): from time import asctime from time import localtime asctime localtime myTime = timestring myTime

我对python还比较陌生,正在研究它。我正在尝试创建一个函数来创建时间消息。我的代码中的单词“year”被突出显示,表明它是无效语法。代码目前还不完整,还有一些事情我需要修复,我现在有点不知所措

我试图解决的问题是:

def timeMessage():

    from time import asctime
    from time import localtime
    asctime
    localtime
    myTime = timestring
    myTime = myTime.split(" ")
    newTimeline = week + " " + month + " " + day + " " year + " " + localtime
    return newTimeline
创建函数timeMessage

论点:无

正文:从时间模块导入asctime函数 使用asctime函数中的星期日、空间、月、空间、日、空间、年、空间时间创建新的时间线 返回新时间线

我的代码:

def timeMessage():

    from time import asctime
    from time import localtime
    asctime
    localtime
    myTime = timestring
    myTime = myTime.split(" ")
    newTimeline = week + " " + month + " " + day + " " year + " " + localtime
    return newTimeline

您需要添加
+
,以显示在
之后包含
年份
变量

像这样:

def timeMessage():

    from time import asctime
    from time import localtime
    asctime
    localtime
    myTime = timestring
    myTime = myTime.split(" ")
    newTimeline = week + " " + month + " " + day + " " + year + " " + localtime
    return newTimeline

你错过了
+
年前的
真不敢相信我错过了,谢谢。