-3

My first language was MATLAB which I'm super in love with but I'm learning Python so what I want to know is there any similar shortcut like whos which shows the type or class of a variable and its size? And is there a "Workspace" so I can see all my variables in pycharm like the pic below?

Ex in MATLAB

Wolfie
  • 27,562
  • 7
  • 28
  • 55

1 Answers1

-1

Muhannad, answering your first question, you can check the type of the variable with the help of type(variableName/ value) function.

Example:

x = 1;

print(type(x)) // <class 'int'>

Now the answer of your second question is, python works on dynamic memory allocation hence the max size of the value that can be stored inside a variable in almost infinite in practical terms. you cant check the exact size of the memory captured by a variable in python(no function is there to acheive that, memory allocation happens behind the scene). and yes there is no workspace provided inside pycharm ide.

however if you are just trying to learn python from scratch, i highly recommend you to go with jupyter notebook insted of pycharm. it will be much begineer friendly. you can check out the link given below for exact installation details.

http://test-jupyter.readthedocs.io/en/latest/install.html

  • [this question](https://stackoverflow.com/questions/449560/how-do-i-determine-the-size-of-an-object-in-python) suggests your comment about not being able to get a variable's size is wrong. Just because the memory allocation is dynamic, it doesn't mean there's not a *current* size on disk being allocated. The same applies to MATLAB. – Wolfie Jun 04 '21 at 13:22
  • ok men, I think so i havent made my statement clear earlier, i just wants to convey that there is no built in function to check the exact size consumed by a variable in python, i have edited my answer, thanks for correcting me. – neel prakash Jun 04 '21 at 13:41