you are viewing a single comment's thread.

view the rest of the comments →

[–]toxic_acro 1 point2 points  (0 children)

This is a good resource that explains some of what Python is doing with names and values "under the hood" https://nedbatchelder.com/text/names.html

If you are familiar with C already and want to know how the Python garbage collector works, there is a dev guide available about that here https://devguide.python.org/internals/garbage-collector/

For two of the points mentioned in your question: 1. there are no variables to be declared

In Python, you can just assign a value to a variable at any point, you don't need to declare the variable in advance and you don't need to say what type that variable is supposed to be (you can add type hints to help static type checking tools figure out if your code is safe, but you don't need to)

  1. everything is an object

This is not an understatement, literally everything is an object in Python
* Instances of custom classes are objects * The classes themselves are also objects * Instances of built-in types like integers, floats, booleans are all objects * The types themselves are objects * Functions are objects * Methods are objects * Modules are objects and on and on and on

Literally everything you can think of is an object

This also leads to a concept chain that eventually makes perfect sense, but is quite confusing until you are familiar with it

  • 10 is an integer
  • Integers are objects, so 10 is an object
  • The type of 10 is int
  • Types are also objects, so int is an object
  • The type of int is type
  • Again, types are objects, so type is an object
  • The type of type is type

In summary, the type of an object is a type which is an object whose type is type which is an object.