[英]Can't define functions in Python
Whenever I write a function and then run it in the Shell, it comes up blank. 每当我编写一个函数然后在Shell中运行它时,它就会变成空白。 I have only been programming for about a month so don't make things very difficult.
我只编程了大约一个月,所以不要让事情变得很困难。
My code looks like this: 我的代码如下所示:
def intro():
print("hello world")
Then when I run it, it . 然后,当我运行它时,它。 No air message pops up.
没有弹出消息。 Except in my code the 2 lines are touching
除了我的代码中的两行
You wrote a function; 您编写了一个函数; now you have to tell it to run the function!
现在您必须告诉它运行功能!
Try 尝试
def intro(): # <= this tells Python what "intro" means
print("hello, world")
intro() # <= this tells Python to actually do it
You need to call your function! 您需要调用您的函数! Do this with
intro()
after the function is defined (Hugh has a nice example above my answer). 定义函数后,使用
intro()
进行此操作(Hugh在我的答案上方有一个很好的示例)。 Better read up on some basics first ;) Codeacademy has an awesome Python course if you're interested. 最好先阅读一些基础知识;)如果您有兴趣, Codeacademy会提供很棒的Python课程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.