功能参数(在Python为例) [英] Function arguments (in Python for example)
问题描述
什么是[功能]参数?使用它们的是什么?结果
我开始学习Python的最近;我是新来的节目,我为这个基本的问题深表歉意。
What are [function] arguments? What are they used for?
I started learning Python very recently; I'm new to programming and I apologize for this basic question.
在每个Python教程中我经历他们谈论的参数的。  我已经看过了这个问题的答案,并发现有很多答案,但他们只是有点太难受,understatnd。我可能只是缺少一些概念背景。结果
所以......当我定义一个函数,什么是括号用于东西呢?
例如:
In every Python tutorial I go through they talk about arguments. I have looked for the answer to this question and have found many answers but they are just a little too hard for me to understatnd. I may just be missing some conceptual background.
So... when I define a function, what are the things in parenthesis used for?
Example:
def hi( This is the part that i dont get):
print 'hi'
编辑:结果
与此相关的两个后续问题后来被关闭,合并在这里,因此一些答案的部分外的环境特征。结果
后续问题是:[转述]
Two follow-up questions related to this one were later closed and merged here, hence the partial out-of-context trait of some of the answers.
The follow-up questions were: [paraphrased]
- Can参数仅用于输入?中搜索
什么是使用参数的其他例子? - 为什么要用论据,而不是函数调用的raw_input?
- 为什么参数的概念路过描述为这样一个强大的东西?的在我看来,我们只是用它们来代替的东西,用户可能在键盘上输入。
- Can arguments only be used for input ?
what are other examples of the use of arguments ? - Why use arguments, rather than having the function call raw_input ?
- Why is the concept of argument passing described as such a powerful thing? it seems to me we're merely using them to replace stuff the user could have type on the keyboard.
推荐答案
在几句话,他们是被传递到功能来告诉它做什么数据。维基百科有更多的细节。
In a few words, they're data that gets "passed into" the function to tell it what to do. Wikipedia has details.
<一个href=\"http://en.wikipedia.org/wiki/Function_argument\">http://en.wikipedia.org/wiki/Function_argument
例如,您的喜()
功能可能需要知道谁打招呼:
For instance, your hi()
function might need to know who to say hello to:
def hi(person):
print "Hi there " + person + ", how are you?"
或数学函数可能需要一个值来操作的:
Or a mathematical function might need a value to operate on:
def square(x):
return x * x
这篇关于功能参数(在Python为例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!