About 511,000 results
Open links in new tab
  1. 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 …

  2. Simplest async/await example possible in Python - Stack Overflow

    Jun 8, 2018 · In case 2, we added async to the normal function. However the event loop will run it without interruption. Why? Because we didn't say where the loop is allowed to interrupt your …

  3. python - How to build a basic iterator? - Stack Overflow

    There are four ways to build an iterative function: create a generator (uses the yield keyword) use a generator expression ; create an iterator (defines __iter__ and __next__ (or next in Python …

  4. 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:

  5. Defining private module functions in python - Stack Overflow

    Python mangles these names with the class name: if class Foo has an attribute named __a, it cannot be accessed by Foo.__a. (An insistent user could still gain access by calling …

  6. python - How to repeatedly execute a function every x seconds?

    I want to repeatedly execute a function in Python every 60 seconds forever (just like an NSTimer in Objective C or setTimeout in JS). This code will run as a daemon and is effectively like …

  7. oop - Private methods in Python - Stack Overflow

    Jan 15, 2022 · You can obfuscate attribute access via metaclasses, and you can make read-only attributes and implement the private/setter/getter pattern with decorators or metaclasses, but …

  8. python - How can I change a global variable from within a …

    The a in the other lines is a local variable, meaning that it only exists inside your test() function. These two variables are completely unrelated to each other, even though they have the same …

  9. Python: How to create a function? e.g. f (x) = ax^2

    Python (and most other computer languages) don't do algebra, which is what you'll need if you want symbolic output like this. But you could have a function f(a,x) which returns the result for …

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

    Jul 11, 2016 · In addition to already existing answers and to make this more confusing: In Python, variables that are only referenced inside a function are implicitly global. If a variable is …

Refresh