About 359,000 results
Open links in new tab
  1. when to use functions in python and when not to ... - Stack Overflow

    Aug 12, 2018 · Functions are a way of compartmentalizing code such that it makes it both easier to read and easier to manage. In this case, there are a few concepts you must understand before implementing functions to solve your problem. Functions follow the format:

  2. In Python, when should I use a function instead of a method?

    The Zen of Python states that there should only be one way to do things- yet frequently I run into the problem of deciding when to use a function versus when to use a method. Let's take a trivial example- a ChessBoard object.

  3. python - How do I call a function from another .py file ... - Stack ...

    #Import defined functions from myfun import * #Call functions Print_Text() c=Add(1,2) Solution2: if this above solution did not work for Colab. Create a foldermyfun; Inside this folder create a file __init__.py; Write all your functions in __init__.py; Import …

  4. python - How can I use a global variable in a function? - Stack …

    Jul 11, 2016 · In Python, the module is the natural place for global data: Each module has its own private symbol table, which is used as the global symbol table by all functions defined in the module. Thus, the author of a module can use global variables in the module without worrying about accidental clashes with a user’s global variables.

  5. python - Why do some functions have underscores - Stack Overflow

    May 24, 2024 · In Python, the use of an underscore in a function name indicates that the function is intended for internal use and should not be called directly by users. It is a convention used to indicate that the function is "private" and not part of the public API of the module.

  6. mean in Python function definitions? - Stack Overflow

    Jan 17, 2013 · In more detail, Python 2.x has docstrings, which allow you to attach a metadata string to various types of object. This is amazingly handy, so Python 3 extends the feature by allowing you to attach metadata to functions describing their parameters and return values. There's no preconceived use case, but the PEP suggests several.

  7. python - How to use a variable defined inside one function from …

    python_file1.py x = 20 def test(): global x return x test() python_file2.py from python_file1 import * print(x) Solution 2: This solution can be useful when the variable in function 1 is not predefined.

  8. python - How do I pass variables across functions? - Stack Overflow

    passing variable from one function as argument to other functions can be done like this. define functions like this. def function1(): global a a=input("Enter any number\t") def function2(argument): print ("this is the entered number - ",argument) call the functions like this. function1() function2(a)

  9. python - Using a dictionary to select function to execute - Stack …

    @Ben Believe me, I am very aware of that, I have 8 years providing software solutions, this is the first time I use Python and I wish I could use many security features from other languages, however I can not control it, I need to make the module somewhat "Read-Only", the costumer asks us to give them "proofs" that the scripting feature is as ...

  10. python - How can I call a function within a class? - Stack Overflow

    I have this code which calculates the distance between two coordinates. The two functions are both within the same class. However, how do I call the function distToPoint in the function isNear? class Coordinates: def distToPoint(self, p): """ Use pythagoras to find distance (a^2 = …

Refresh