Python Forum
Understand what it means that everything in Python is an object...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Understand what it means that everything in Python is an object...
#1
Hello everyone,

I am new to the forum and relatively new to Python. I understand that Python considers everything as an "object". Lists, variables, functions, classes, methods are all considered to be objects.

However, I believe the use of the term "object" is different from the use of the term object used in OOP. Any programming language is independent of the programming paradigm it may use. But it seems that Python, by calling everything an object, is intrinsically connected to OOP even if I believe it is not the case since we can code in Python without doing OOP...

Is that correct? Could anyone clarify if there is any similarity, connection or lack of it between the usage of term "object" in Python and in OOP?

Thanks,
bytecrunch
Reply
#2
When we say everything is an object it has the same meaning as in OOP paradigm. Everything, e.g. built-i types or collections, has attributes - properties and methods. Even functions are objects. And you can subclass the built in types.

In more narrow sense object is the base class from which everything inherits in python
bytecrunch likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you,

So is it correct to say that Python is inherently an object oriented programming language?
Reply
#4
Thank you,

So is it correct to say that Python is inherently an object oriented programming language?
Reply
#5
(Feb-05-2021, 09:18 PM)bytecrunch Wrote: Thank you,

So is it correct to say that Python is inherently an object oriented programming language?

I think the problem is that Python is often used as a scripting language. But if fact, like buran mentioned, everything in python is an object. Even a simple variable like a string or integer is an object, which has its own attributes, methods etc.

So if you ask me, yes. Even if people use Python code 'just' as a scripts, they are in fact working with plenty of objects.
bytecrunch likes this post
Reply
#6
Thanks Jeff900,

Sorry, I am a beginner. What do you mean exactly when you say "just" Python scripts? To me, a script is how we call a Python program.

And you said, everything is an object which seems to be one of the hallmarks of OOP. But coding in Python does not imply OOP.
Reply
#7
(Feb-06-2021, 12:33 AM)bytecrunch Wrote: Thanks Jeff900,

Sorry, I am a beginner. What do you mean exactly when you say "just" Python scripts? To me, a script is how we call a Python program.

And you said, everything is an object which seems to be one of the hallmarks of OOP. But coding in Python does not imply OOP.

With scripting I basically mean you will just run some code at once. To analyse data for example, or do something with a bunch of files etc. It has a specific beginning and an end, unlike programs that will be kept alive one way or another. But I realise this is my opinion and kind of subjective...

But to give an example for the fact that even in a simple 'script' you're using objects, take a look at the following code.

>>> number = 1
>>> type(number)
Output:
<class 'int'>
In this example you can see a simple integer is not just an integer. It is a class (object) which is used to define integers. You can create your own classes in Python to create your own specific objects. Creating your own classes may feel more like OOP, but in fact with using Python you're working with objects all the time.
bytecrunch likes this post
Reply
#8
Thank you.

Some say that Python is not a "pure" object oriented language (I guess some language like smalltalk are) but I now believe it is not completely correct.

A module is also an object like anything else in Python. And the module's attributes are the functions and classes that the module contains, correct?

thanks again!
Reply
#9
Yes, that's correct.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python update binary object (override delivered Object properties) pierre38 4 1,773 May-19-2022, 07:52 AM
Last Post: pierre38
  Understand order of magnitude performance gap between python and C++ ThelannOryat 4 2,718 Mar-17-2021, 03:39 PM
Last Post: ThelannOryat
  Trying to understand the python code spalisetty 2 1,875 Mar-16-2020, 08:11 AM
Last Post: javiertzr01
  I do not understand why my python looks different from tutorials. noodlespinbot 2 5,134 Oct-12-2019, 09:56 PM
Last Post: noodlespinbot
  what "return" means? PY_beginner 9 3,912 Oct-10-2019, 07:18 AM
Last Post: newbieAuggie2019
  I dont understand bytes in python. blackknite 3 4,019 Oct-02-2019, 07:39 PM
Last Post: Gribouillis
  effective means to flip boolean values? Exsul 3 4,368 Aug-25-2019, 03:58 PM
Last Post: Exsul
  what means in Python the "->"? lsepolis123 2 2,004 Aug-22-2019, 08:08 AM
Last Post: DeaD_EyE
  Smtplib: What does context argument means? Pythenx 1 3,087 Mar-27-2019, 06:25 PM
Last Post: nilamo
  Trying to understand how import works in python patrick99e99 3 3,879 Jun-12-2018, 04:48 AM
Last Post: patrick99e99

Forum Jump:

User Panel Messages

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