Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Visual Studio Code
#1
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!
Reply
#2
(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]
Reply
#3
Hey, thank you.

But what does
choices = _inst.choices
mean?
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 1,050 Nov-15-2023, 06:56 PM
Last Post: jst
  How to set PYTHONPATH in Visual Studio Code? aupres 5 4,238 Aug-15-2023, 03:51 PM
Last Post: snippsat
  how do I open two instances of visual studio code with the same folder? SuchUmami 3 894 Jun-26-2023, 09:40 AM
Last Post: snippsat
  Visual Studio Code venv ibm_db error mesi1000 7 2,833 Nov-13-2022, 12:36 AM
Last Post: snippsat
  debugging help on Visual Studio Code mg24 12 2,024 Oct-02-2022, 12:18 AM
Last Post: mg24
  Problem with importing Python file in Visual Studio Code DXav 7 5,121 Jun-15-2022, 12:54 PM
Last Post: snippsat
  Visual Studio Code Intellisense for Imported Modules Not Working hockinsk 1 2,732 Apr-23-2022, 04:41 PM
Last Post: deanhystad
Photo Visual studio code unable to color syntax on python interpreter tomtom 4 6,924 Mar-02-2022, 01:23 AM
Last Post: tomtom
  compile error Visual Studio Code jamie_01 2 1,698 Jan-25-2022, 09:36 AM
Last Post: Larz60+
  Calling python from c++ in visual studio pdk5 0 2,174 May-24-2021, 10:18 AM
Last Post: pdk5

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020