On Sat, 16 Apr 2022 at 04:51, Python wrote:
>
> Cecil Westerhof wrote:
> > In C when you declare a variable static in a function, the variable
> > retains its value between function calls.
> > The first time the function is called it has the default value (0 for
> > an int).
> > But when the funct
Cecil Westerhof wrote:
In C when you declare a variable static in a function, the variable
retains its value between function calls.
The first time the function is called it has the default value (0 for
an int).
But when the function changes the value in a call (for example to 43),
the next time
Thanks for the multiple answers. I was pleasantly surprised.
I have something to think about. :-D
In principle I selected a solution for the problem for which I asked
it, but I first have to finish some other stuff. I hope to find time
to implement it next week.
Everyone a good weekend and Easter
Yes, python has something like that. In fact, two things.
1) Generator. Use a "yield" statement. Every call "yields" a new value.
The state of the function (local variables) is remembered from each previous
call to the next.
2) In a file, declare a variable to be global. In the funct
On Fri, 15 Apr 2022 at 03:53, Sam Ezeh wrote:
>
> I've seen people use function attributes for this.
> ```
> Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def function():
> ... print(function.var
Cecil Westerhof wrote at 2022-4-14 17:02 +0200:
>In C when you declare a variable static in a function, the variable
>retains its value between function calls.
>The first time the function is called it has the default value (0 for
>an int).
>But when the function changes the value in a call (for ex
Cecil Westerhof writes:
> In C when you declare a variable static in a function, the variable
> retains its value between function calls.
> The first time the function is called it has the default value (0 for
> an int).
> But when the function changes the value in a call (for example to 43),
> t
I've seen people use function attributes for this.
```
Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def function():
... print(function.variable)
... function.variable += 1
...
>>> function.variab
Am 14.04.2022 um 17:02 schrieb Cecil Westerhof via Python-list:
> In C when you declare a variable static in a function, the variable
> retains its value between function calls.
> The first time the function is called it has the default value (0 for
> an int).
> But when the function changes the va
> On 14 Apr 2022, at 16:28, Cecil Westerhof via Python-list
> wrote:
>
> In C when you declare a variable static in a function, the variable
> retains its value between function calls.
> The first time the function is called it has the default value (0 for
> an int).
> But when the function c
10 matches
Mail list logo