How to repeat a function with change some variables inside of the function? PYTHON 3.4

Jesus Baker

i'm beginner and I would to like to know if there is some way to make a function that repeats itself changing valor the valor of some variables...

For example:

def example():
    box1.delete(0,END) #Here I would like to change the variable "box1" to "box2" and "box3"
    get1=box1.get() #Here I would like to change the variable "box1" to "box2" and "box3"

Well, I think that is all. I hope you can help me. Thank you!

mgilson

Usually, you would make box an argument to the function and call it repeatedly with all the boxes you want to operate on:

def example(box):
    box.delete(0, END)
    get = box.get()
    ...

for box in box1, box2, box3, box4:
    example(box)

if example actually returns something (e.g. the data that box.get returned), you can use a list comprehension.

boxes = (box1, box2, box3, box4)
data = [example(box) for box in boxes]

Now data is a list with one element from each element in boxes.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

What is the Python equivalent of static variables inside a function?

From Dev

Python: How to stop a looping function inside a function?

From Dev

Anomaly in accessing global variables inside a function in Python 2/3

From Dev

How to access variables inside a function in javascript

From Dev

How to properly execute a function inside ng-repeat

From Dev

How to assign variables to an aliased Controller inside a function?

From Dev

why can't I change the variables using kwargs inside a function?

From Dev

How to change the value of sum function inside the query?

From Dev

Repeat Function inside PHP

From Dev

Assigning variables inside a function

From Dev

How to initiate forEach function inside ng-repeat

From Dev

Change Function Name inside For Loop Python

From Dev

Python how to use (variables inside function F1) inside function (F2 which is inside F1)

From Dev

Change Function Name inside For Loop Python

From Dev

Accessing variables that are inside a function

From Dev

ng-repeat with function inside

From Dev

change pointed instance inside a function in python

From Dev

How to access variables inside a function in javascript

From Dev

How to make API function call inside ng-repeat?

From Dev

How to assign variables to an aliased Controller inside a function?

From Dev

why can't I change the variables using kwargs inside a function?

From Dev

How to create local variables inside the main function?

From Dev

function inside ng-repeat called 4 times (AngularJs)

From Dev

How can I change user inside function

From Dev

How to change value inside function

From Dev

How to make Class function repeat it self in python?

From Dev

How to use a variable inside a function which is defined (variable) in some other function within a class in python?

From Dev

How to change a variable declare inside a function in javascript

From Dev

PHP variables inside a function

Related Related

  1. 1

    What is the Python equivalent of static variables inside a function?

  2. 2

    Python: How to stop a looping function inside a function?

  3. 3

    Anomaly in accessing global variables inside a function in Python 2/3

  4. 4

    How to access variables inside a function in javascript

  5. 5

    How to properly execute a function inside ng-repeat

  6. 6

    How to assign variables to an aliased Controller inside a function?

  7. 7

    why can't I change the variables using kwargs inside a function?

  8. 8

    How to change the value of sum function inside the query?

  9. 9

    Repeat Function inside PHP

  10. 10

    Assigning variables inside a function

  11. 11

    How to initiate forEach function inside ng-repeat

  12. 12

    Change Function Name inside For Loop Python

  13. 13

    Python how to use (variables inside function F1) inside function (F2 which is inside F1)

  14. 14

    Change Function Name inside For Loop Python

  15. 15

    Accessing variables that are inside a function

  16. 16

    ng-repeat with function inside

  17. 17

    change pointed instance inside a function in python

  18. 18

    How to access variables inside a function in javascript

  19. 19

    How to make API function call inside ng-repeat?

  20. 20

    How to assign variables to an aliased Controller inside a function?

  21. 21

    why can't I change the variables using kwargs inside a function?

  22. 22

    How to create local variables inside the main function?

  23. 23

    function inside ng-repeat called 4 times (AngularJs)

  24. 24

    How can I change user inside function

  25. 25

    How to change value inside function

  26. 26

    How to make Class function repeat it self in python?

  27. 27

    How to use a variable inside a function which is defined (variable) in some other function within a class in python?

  28. 28

    How to change a variable declare inside a function in javascript

  29. 29

    PHP variables inside a function

HotTag

Archive