How do you call a function in a function?

后端 未结 4 1572
耶瑟儿~
耶瑟儿~ 2020-12-18 06:56

I have a function and I\'m making another one in which I need to call the first function. I don\'t have experience in Python, but I know that in languages like MATLAB it\'s

4条回答
  •  爱一瞬间的悲伤
    2020-12-18 07:22

    2 way to use a function within an other:

    1. You define the square() function in another .py file (ex: myfile.py) and then, you can import the function this way:
    from myfile import square
    
    def newFunction():
       square()
    
    1. You define the function in the same file and then there is no need for the import and you can use square() directly.

提交回复
热议问题