+ 1

Do we have "define" in python like we have in C/C++?

Hello every body. Is there DEFINE command in Python like C/C++?

13th Apr 2017, 6:44 PM
Ctrl_Alt_Del
Ctrl_Alt_Del - avatar
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
13th Apr 2017, 7:21 PM
Shraddha
Shraddha - avatar
+ 1
you can use with ... as ... code.
13th Apr 2017, 9:09 PM
Ali Mohammadpour
+ 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(++)
14th Apr 2017, 6:33 PM
Amaras A
Amaras A - avatar
0
Crap srry ik that now
18th Apr 2017, 2:52 PM
DRAGONGAMING
DRAGONGAMING  - avatar
0
I wrote that when I didn't even know what def did
18th Apr 2017, 2:52 PM
DRAGONGAMING
DRAGONGAMING  - avatar
0
I finished Python but I'm gunna go through the course again
18th Apr 2017, 2:53 PM
DRAGONGAMING
DRAGONGAMING  - avatar