Hey,
I use Visual Studio Code and the Python extension.
When I hover over "random.choices(...)" it shows, that choices is a variable.
I don't understand. Isn't it a function?
Thank you!
(May-16-2023, 09:52 PM)NewPi Wrote: [ -> ]I use Visual Studio Code and the Python extension.
When I hover over "random.choices(...)" it shows, that choices is a variable.
I don't understand. Isn't it a function?
It's a method if look at source code.
Why it show a variable,is that in source there is this line
choices = _inst.choices
So
_inst.choices
is the method,if hover over will return.
(method) def sample(
population: Any,
k: Any,
*,
counts: Any | None = None
) -> (list | Any)
Chooses k unique random elements from a population sequence.
.....
You can get to this code bye press
Ctrl
and click when hover over choices.
![[Image: owVChQ.png]](https://imagizer.imageshack.com/v2/xq70/923/owVChQ.png)
It's just name change to something easier to understand.
In Source.
randrange = _inst.randrange
sample = _inst.sample
shuffle = _inst.shuffle
choices = _inst.choices
...
It's similars as this,i want egg as simpler name.
def _inst_egg():
return 'Some eggs'
egg = _inst_egg()
print(egg)
Output:
Some eggs