简体   繁体   English

使用另一个函数的参数-Python

[英]Using an argument from another function - Python

Let's suppose I have 假设我有

def perrin(a):
    if true:
    #Do something

def sequence(string,n)
    if string == "name":
        perrin(n)

I just want perrin to take the n argument from the sequence, is this the correct way of doing it? 我只希望perrin从序列中获取n参数,这是正确的方法吗?

Yes it's fine you need only to edit two syntax errors: 是的,您只需编辑两个语法错误就可以了:

  1. Capital 'T' in True True大写字母“ T”

  2. Colon ( : ) after the function definition def sequence(string, n) . 冒号( : )之后的函数定义def sequence(string, n)

The updated code looks like this 更新后的代码如下所示

    def perrin(a):
        if True:
            #do something here

    def sequence(string,n):
        if string == "name":
            perrin(n)

If both definitions are in the same class it looks fine to me. 如果两个定义都在同一个类中,对我来说很好。 You do need to have True or False with a capital letter, else it won't regocnize is aa boolean. 您的确需要带大写字母的True或False,否则布尔值将不会重新定位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用从函数返回的文件作为python中另一个函数的参数 - Using a file returned from a function as an argument for another function in python 如何将参数从一个 function 传递给 Python 中的另一个? - How to pass argument from one function to another in Python? Python-将函数作为参数传递给另一个函数 - Python - passing a function as an argument to another function 通过Python中的另一个函数传递函数参数 - Passing a function argument through another function in Python python将函数传递给另一个函数 - python pass function with argument to another function 将函数参数作为参数传递给python中的另一个函数 - pass a function parameter as an argument to another function in python 如何从列表中传递一个参数,在Python中的内置函数map()中传递另一个参数? - How to pass one argument from list and another argument in the built-in function map() in Python? 将参数传递给函数,该参数必须作为参数传递给python中的另一个函数 - Passing an argument to the function , which has to be passed as an argument to another function in python 通过装饰器使用一个函数作为另一个函数的参数 - Using a function as an argument in another function through decorators 使用部分评估的 function 作为另一个 function 的参数 - Using a partially evaluated function as an argument of another function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM