6 odpowiedzi
+ 5
No @DRAGONGAMING def in python is used for functions. #define in c++ is used for creating global variables or macros. In python you can access global variables normally like any other variable, but while defining use the keyword global.
Eg 1:
def myFunc():
Var = "locally defined" # Defined only in local context
print Var #prints locally defined
myFunc()
print Var #gives error
Eg2 :
def myFunc():
global Var # Defined only in global context
Var = "globally defined"
print Var #prints globally defined
myFunc()
print Var #also prints globally defined
+ 1
you can use with ... as ... code.
+ 1
@ali Not really: the with statement uses a context manager, that does some setup before your code and some destruct job afterwards. So It's not really an equivalent of #define in C(++)
0
Crap srry ik that now
0
I wrote that when I didn't even know what def did
0
I finished Python but I'm gunna go through the course again