About 144,000 results
Open links in new tab
  1. mean in Python function definitions? - Stack Overflow

    Jan 17, 2013 · def function(arg)->123: It's simply a return type, integer in this case doesn't matter which number you write. like Java: public int function(int args){...} But for Python (how Jim Fasarakis Hilliard said) the return type it's just an hint, so it's suggest the return but allow anyway to return other type like a string..

  2. What is a DEF function for Python - Stack Overflow

    Sep 10, 2013 · def - Tells python we are declaring a function; square - The name of our function (- The beginning of our arguments for the function; number - The list of arguments (in this case just one)) - The end of the list of arguments: - A token to say the body of the function starts now; The following newline and indent then declare the intentation ...

  3. Function for factorial in Python - Stack Overflow

    The easiest way is to use math.factorial (available in Python 2.6 and above): import math math.factorial(1000) If you want/have to write it yourself, you can use an iterative approach: def factorial(n): fact = 1 for num in range(2, n + 1): fact *= num return fact or a recursive approach:

  4. How to use the def function in IF or ELSE/ ELIF satement in python?

    Jan 3, 2016 · I have a sub program that uses a def option, so if i ever want to repeat the program. Eg: def op1(): print ("Something Something") So I just write in the program: op1() which makes the program run. Now I have a lot of subprograms each one with a different def so I can run them by easily. eg: def op1(): def op2(): def op3():

  5. function - python calling a def() inside of def() - Stack Overflow

    Aug 1, 2018 · Python function from another def function. 0. Using a function within a function. 0. Calling a function ...

  6. function is not defined error in Python - Stack Overflow

    Sep 5, 2016 · $ python program.py Traceback (most recent call last): File "program.py", line 3, in <module> pyth_test(1,2) NameError: name 'pyth_test' is not defined As noted, python cannot find the module for the reasons outlined above. For that reason, you should keep your declarations at top. Now then, if we run the interactive python session:

  7. python - How to stop a function - Stack Overflow

    A simple return statement will 'stop' or return the function; in precise terms, it 'returns' function execution to the point at which the function was called - the function is terminated without further action. That means you could have a number of places throughout your function where it might return. Like this:

  8. How to define global function in Python? - Stack Overflow

    Jan 13, 2015 · Functions are added to the current namespace like any other name would be added. That means you can use the global keyword inside a function or method:

  9. python - How to put a define inside a define function - Stack …

    Apr 3, 2015 · Until the inside function is a attribute of the outside function there is no way to call it using the name of the enclosing function. In case. def move(): def left(): i.e. If there is only one function inside a function it is feasible to return left() from move function. However in this case there are multiple functions inside move function scope.

  10. python - How do I define a function with optional arguments?

    A Python function can take in some arguments, take this for example, def add(x,y): return x+ y # calling this will require only x and y add(2,3) # 5 If we want to add as many arguments as we may want, we shall just use *args which shall be a list of more arguments than the number of formal arguments that you previously defined ( x and y ).

Refresh