+ 1

Difference of "def func(x) and def func ()"

Aside from the spellings, are there any? While I code it often causes me an error or is it the arguments inside the func that causes it? I believe it was mentioned from a topic in Python but after proceeding to many lessons I can't quite remember. Thanks in advance for your response😊😊😊

16th May 2019, 7:02 AM
bimyou
bimyou - avatar
2 RĂ©ponses
+ 2
def func(x): #now we expect x and we will able to use x x = x*x print(x) func(2) ==> 4 def func2(): # if we need to use any varible we have to assing it x = 2*2 print(x) func2() ==> 4 same result but second functions is not dynamic you had to assign values to variables.
16th May 2019, 8:14 AM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 5
Well atleast when you define as "def func(x)", you must always pass one argument when you call the function.
16th May 2019, 7:16 AM
Seb TheS
Seb TheS - avatar