I have a question about Python def function

Asked 2 years ago, Updated 2 years ago, 12 views

def func(a,b,c):
    ~~
    f1=open("c:\\jupyurt\\a.txt","w"); 
    f1.write()
    f1.close()

def func2(A,B,C):
    ~~
    f2=open("c:\\jupyurt\\a.txt","w"); 
    f2.write()
    f2.close()

As in the above example, the two functions are defined and the result values are represented in the file.

Is there any code that can use func(a,b,c) in the second function?

Actually, when I tried it, func(a,b,c) was printed on f1, so f2 was not produced at all...

python

2022-09-20 19:39

1 Answers

def func1(a, b, c):
    #Blahblahblahblahblah
def func2(A, B, C):
    func1(A,B,C)

func1Direct scope is discharged, so if you want to modify it in another scope, If you're going to use the global keyword and just run it, you can call it~


2022-09-20 19:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.