簡體   English   中英

Python函數無法正常工作“幫助”

[英]Python function is not working “Help”

我要向您展示的第一個代碼

def spam():
    """Prints the word eggs!"""

    egg = "Eggs!"

    print (egg)



spam()

但這不起作用,我不明白

def spam():
    """Prints the word eggs!"""

    print "Eggs!"



spam()

原來我在打印“雞蛋!”中缺少括號。 應該已經打印(“雞蛋!”)

您必須使用python 3,因為它需要帶print語句的括號。 試着做:

print("Eggs!")

代替:

print "Eggs!"

注意您的第一個函數如何帶有括號:

print(egg)

這就是為什么它起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM