功能参数(在Python为例) [英] Function arguments (in Python for example)

查看:147
本文介绍了功能参数(在Python为例)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是[功能]参数?使用它们的是什么?结果
我开始学习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 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆