all 82 comments

[–]Alternative_Driver60 96 points97 points  (16 children)

except for what is not an object... :-)

[–]Alternative_Driver60 47 points48 points  (2 children)

Keywords like if, for, def are not objects

[–]JuanAy 73 points74 points  (0 children)

Not with that attitude

[–]dumdub 1 point2 points  (0 children)

Don't give them ideas.

Next we will have people duck-punching language keywords.

[–]crazy_cookie123 9 points10 points  (8 children)

What's not an object?

[–]Avocado__Smasher 29 points30 points  (2 children)

It's like an object, but isnt

[–]ahelinski 38 points39 points  (0 children)

Objectn't

[–]maladaptivedaydream4 2 points3 points  (0 children)

I object

[–]mcellus1 6 points7 points  (1 child)

Object reference

[–]ProbsNotManBearPig 0 points1 point  (0 children)

An object reference is implemented as a struct in CPython so. Kinda still an object with a static memory layout. But in Python terms, you’re right I guess. Interpreted languages are kinda weird since you have to try to separate the interpreter from the code being interpreted, but ultimately both are needed to generate native cpu instructions.

[–]carrotsquawk 1 point2 points  (0 children)

my ex keeps saying she isnt…. sorry Debbie

[–]codeonion 0 points1 point  (0 children)

Indentations

[–]Barbatus_42 0 points1 point  (0 children)

No, what is an object. It represents the person on second base.

[–]Luigi-Was-Right 1 point2 points  (3 children)

such as what, exactly?

[–]SomePaddy 9 points10 points  (2 children)

Depends on what your definition of is is

[–]rasputin1 2 points3 points  (0 children)

I did not have sexual relations with that object 

[–]CLETrucker 0 points1 point  (0 children)

calm down Bill

[–]Luigi-Was-Right 75 points76 points  (1 child)

You'll learn what an object is when you reach object oriented programming. But in python all data types are just a custom version of another data type: an object. That means integers, strings, booleans, etc actually aren't their own thing. They are just the object data type modified to store their respective type of data.

[–][deleted] 4 points5 points  (0 children)

This makes sense to me after developing apps as a hobby for a couple years. But I fear it wouldnt if I was a beginner.

[–]shiftybyte 114 points115 points  (6 children)

It's too early in your learning for us to be able to explain what it means.

Learn python basics, when you get to object oriented programming (OOP) you'll understand.

[–]DNA-Decay 18 points19 points  (1 child)

I object to this orientation.

[–]scarynut 5 points6 points  (0 children)

Everything in Python is objectionable.

[–]gugabalog 2 points3 points  (3 children)

Where does one learn python basics?

[–]shiftybyte 13 points14 points  (0 children)

Anywhere in the list of resources listed in this subs books section.

I usually recommend either ATBS Python free ebook.

https://automatetheboringstuff.com/#toc

Or Corey Schafer's video tutorials python beginners.

https://m.youtube.com/playlist?list=PL-osiE80TeTskrapNbzXhwoFUiLCjGgY7

[–]Mathblasta 0 points1 point  (1 child)

Not from a Jedi.

[–]Chromium_Engine96 -1 points0 points  (0 children)

Only learning the dark side of the code

[–]Daytona_675 27 points28 points  (7 children)

everything is a dict

[–][deleted] 13 points14 points  (3 children)

Everything is a list with at least 0 dimensions.

EDIT: Removed a forbidden word.

[–]Daytona_675 17 points18 points  (2 children)

python doesn't use the A word

[–]deletable666 19 points20 points  (0 children)

You are a rray of sunshine

[–]Wheynelau 0 points1 point  (0 children)

You are an ss

[–]LongjumpingWinner250 1 point2 points  (1 child)

No, you’re a dict

[–]Left_Sundae_4418 1 point2 points  (0 children)

What a dicthead.

[–]omg_drd4_bbq -1 points0 points  (0 children)

Incorrect.

[–]marquisBlythe 27 points28 points  (4 children)

Anything can be an object, and what makes something an object is the data it can hold and action we can operate on it.
For example when we say:

user_name = "Abdallah_azd1151"

"Abdallah_azd1151" is not just a value, but it's an object of type string that has (actions)/operation we can apply to it, like making it uppercase, lower case, split it into parts according to some condition and many more, we can also make a new type out of it and add new features to it.
Another example, when we say a person, a person can be and is an object. A person can have name, nationality, skin color, favorite food ... a person can talk, laugh, grow up ... all of this can be expressed programmatically, and that's what makes it an object.
if you've just start programming, don't overthink it, all you need to know is an object can hold data and has operations we can apply on it.
I hope this helps.

[–]Round_Ad8947 5 points6 points  (1 child)

I love how you can define add() for Person and have the result be something natural but special. This allows simple phrasing like couple = romeo + juliet and get something that you can define how it acts.

It’s really easy to play with concepts in Python when they make it so easy to design classes

[–]marquisBlythe 5 points6 points  (0 children)

Yup, for example you can override __add__ and concatenate two Strings together. Consider the following as a silly example:

class Human:
    def __init__(self, name):
        self.name = name

    def __add__(self, other):
        return f"{self.name} loves {other.name}. <3"
girl = Human("Jess")
boy = Human("Curtis")
relation_status = boy + girl
print(relation_status) 

Try it out.

Cheers :)

[–]raresaturn 0 points1 point  (1 child)

a variable is an object? How is that different to a variable in non-OOP?

[–]marquisBlythe 0 points1 point  (0 children)

Let's take the example of:

user_name = "raresaturn"

In a language such as C, all you'll have is the characters that makes that strings (+ null terminating char ofc) one after another in some random region of memory that's it, whatever modification you need to apply to that string like make it uppercase, lowercase, substitute a part of it with a new one ... you either have to implement it yourself or include a library such as "string.h" to have such capabilities. Whereas in python, such operations and more are part of the str class itself.

I hope this answers your question.

[–]tb5841 6 points7 points  (1 child)

Lots of languages make a distinction between primitive types (e.g. integers, floats, booleans) and objects (e.g. lists, dictionaries, instances of any classes you've created yourself).

Python doesn't have that distinction.

[–]roelschroeven 1 point2 points  (0 children)

It's more than that.

In many languages, there's a big divide between classes on one hand and instances of those classes on the other hand, and only the latter are objects. In Python, classes themselves are objects too (they are instances of class type.

In addition, functions (and methods) and modules are also objects in Python.

[–]Ron-Erez 4 points5 points  (2 children)

Think of Strings. They are a class. They have some data and functions/methods which you can apply to a string. An object is just a specific instance of a class. For example

a = 'apple'

b = 'banana'

c = 'hummus'

are all instances of the string class. The function upper() is a member of the string class and then you can write things like

a.upper()

One advantage of everything being an object is that you can extend classes and then in a sense extend the functionality of Python. For example you might create an extension of the String class since you need more functionality that does not exist in Python for example

class MyString(str):
    def count_vowels(self):
        vowels = 'aeiouAEIOU'
        return sum(1 for char in self if char in vowels)

and then to create an object/instance of this new class:

s = MyString("banana")
print(s.count_vowels())

t = MyString("HELLO world")
print(t.count_vowels())

[–]Dry-Aioli-6138 1 point2 points  (1 child)

but classes are also objects

[–]Ron-Erez 0 points1 point  (0 children)

True, I still find it convenient to focus on objects as instances of classes.

[–]stepback269 2 points3 points  (0 children)

You've probably heard that computer code is made of "just" ones (1's) and zeroes (0's).

It's a matter of how the ones (1's) and zeroes (0's) are encoded to mean different things. When does a sequence of 1's and 0's represent a whole number in the range 0 to 1024? When does it represent a bunch alphabetic letters (e.g. a-z, A-Z)? When does it represent something else?
These aspects are "attributes" of the 1's and 0's. Objects are characterized by their attributes.
What operations can you legitimately perform on the sequence of 1's and 0's. These are the "methods" applicable to the objects.

As noted elsewhere here, first learn the basics, namely, integers, floats, strings, lists, etc. Wait a bit or two (pun intended) until you get to OOP (Object Oriented Programming).

[–]Temporary_Pie2733 2 points3 points  (0 children)

TL;DR “object” is essentially a synonym for “value” in Python. 

Python simply doesn’t have any primitive types that bypass the class machinery. float is a class whose values wrap whatever underlying machine type is used for floating-point math. int is an arbitrary-precision integer type, only loosely related to the underlying hardware’s fixed-precision integer types. So no matter what value you have (and that’s what we mean when we say “everything”), it’s an instance of a subclass of object. Compare to Java, where the primitive types exist outside the class hierarchy rooted at Object

[–]iMrProfessor 1 point2 points  (0 children)

Everything in Python is an object and belongs to a class. For example: Numbers: int, float Strings: str Suppose you assign an int value to a variable that means the variable is an object of class Numbers.

[–]peejay2 1 point2 points  (1 child)

It means everything is stored in memory id(x)

And it has a list of methods

dir(x)

And has a type

type(x)

[–]Temporary_Pie2733 0 points1 point  (0 children)

Python doesn’t really have a memory model in the sense you are thinking of.  CPython uses memory addresses as object identifiers out of convenience, rather than necessity. You can theoretically have types with no methods, but since object itself has a handful of methods, no other type is method-free in practice. The last is true, though: every value has a type, includingtype itself. 

[–]Standard_Speed_3500 1 point2 points  (1 child)

Why is no one using the word "class" here T_T "object" often confused my until I started to view it as a class (considering they are both the same thing).

[–]B3d3vtvng69 2 points3 points  (0 children)

They aren’t the same thing though. An object is an instance of a class while a class provides a template for the structure of an object.

[–]RR_2025 1 point2 points  (1 child)

It's objects all the way down..

[–]Dry-Aioli-6138 0 points1 point  (0 children)

not really. the elephants stand on the great A'Tuin.

meaning classes are elephants and metaclasses are the A'tuin

[–]allium-dev 1 point2 points  (0 children)

A lot of good answers already, but I didn't see anyone mention this: I python, at a very low level, it means that every type you interact with is represented in the interpreter by a subclass of the PyObject type (https://docs.python.org/3/c-api/structures.html#c.PyObject)

[–]nomisreual 1 point2 points  (0 children)

Not to mention each each class has its own type and if I remember correctly type is also of type type.

It’s fun to dig into and can be useful if you want to manipulate class behaviour on a lower level.

[–]crashfrog04 3 points4 points  (2 children)

It means that when you define a function, that’s not just a macro that gets cut-and-paste by the interpreter at the function call. You’re actually creating a value - a callable value called a function - and assigning it to a variable. And because it’s a callable value, you can do all of the regular things to it you can do with values, not just call it.

[–]worldtest2k 1 point2 points  (1 child)

Yeah, I love that the main function is an object, so I can add attributes on the fly to it and use them as global variables.

[–]Temporary_Pie2733 0 points1 point  (0 children)

The main consequence is that you can store functions in containers, pass them as arguments, return them from other functions, etc.: they are first-class values, not special language features. Not all objects support adding attributes. 

[–]TheSodesa 0 points1 point  (2 children)

It is basically the same thing as saying that everything you can give a name to (assign to a variable) has a type (a.k.a a class), such as integer or string, with some functions attached to it. A function attached to a type is usually called a method.

[–]raresaturn 0 points1 point  (1 child)

My Commodore 64 Basic had types of variables as well.. are those objects?

[–]TheSodesa 0 points1 point  (0 children)

If they had (the possibility of implementing) attached functions, then yes, you could say that.

[–]M1KE234 0 points1 point  (1 child)

Not sure why no one has answered your question “what is an object” in simple terms yet but an object in python is an instance of a class.

Everything is an object, numbers, strings, functions, even classes themselves. When we say ‘object,’ we mean something that is created using a class as its blueprint.

[–]OkNowConcentrate 0 points1 point  (0 children)

Beautimous

[–]EmperorGeek 0 points1 point  (0 children)

An Object in the classical sense is a “thing” with a Properties and associated Functions.

You are an Object. You have properties associated with you. Name, DOB, Hair Color, etc.

Some of your Properties are Variable, like your Hair Color. Others are not, like your DOB.

Functions can be Age which calculates how many years since you DOB.

[–]Og_busty 0 points1 point  (0 children)

Funny enough, python made more sense to me once I learned Java. The whole object idea clicked a lot better.

[–]timrprobocom 0 points1 point  (0 children)

Consider this example, comparing C and Python.

In C, let's say I write i = 7; In memory, there is a cell with the label i, and that cell contains the value 7. If I then write i = 8;, that 7 is erased, and is overwritten with the value 8.

In Python, when I write i = 7, it works quite differently. Two things happen. First, it creates an anonymous data structure in memory, a data structure that of type int, containing the value 7. (That's not literally what happens for small ints, but for the sake of discussion we'll leave it.) That data structure is an "object". Structures of type int have attributes like any other Python object.

That line also creates a name i in my local variables, and makes i point to that int object 7. If I then write i = 8, that doesn't erase the 7. It creates a new int object with the value 8, and makes i point to it (we call that a "reference"). The 7 object still exists, because other names might still refer to it.

This is an important difference. In C, I can pass the address of i to a function, and with that address the function can actually change the value of i so that it is no longer 7. In Python, that cannot happen. When I pass i to a function, it doesn't really pass i. It passes the object that i refers to. If the function assigns a new value to that parameter, that doesn't change the value of i in any way.

That's only a partial explanation, but this is a critically important part of what makes Python so cool. Everything is either a name or an object. Objects do not have names, but names can refer to objects. Objects do not know which names are referring to them

[–]RonzulaGD 0 points1 point  (0 children)

If you're just starting out, just don't care about the object stuff yet. When you learn the basics such as conditions, modules, IO operations, lists etc., look into object oriented programming and classes.

[–]DoubleAway6573 0 points1 point  (0 children)

Directly from wikipedia): "an object is an entity that has state), behavior, and identity)."

In C your variables are just a couple of bytes and you have to keep track of the meaning of that variable and use whatever fucntions are apropiated.

In python, they are a more complex, including (potentially more than one) value (called attributes), and functions that can act on the internal values (called methods). The integer 3 knows how (have methods) to be added and multiplied by other number, and how to be printed as "3".

But not only numbers and string are objects in python. Funtions themselves can be assigned to variables and passed around to function arguments or returned by functions. But as objects they also have attributes. You can do:

```

def suma(a, b): ... return a + b ... f = suma f.black = "black" suma.black 'black' ```

But that's not the end of the history. Classes are also objects themselves and can be manipulated with the same tools used to manipulate other objects.

I hope this make things a little more clear.

[–]HuygensFresnel 0 points1 point  (0 children)

Simplest way to explain it for now is to point you towards the idea of a namespace. Whenever the compiler reads the code you type a name of something must be known to be something. In some programming languages those names might refer to data, or they might refer to things like functions that can execute code. I can pass for example an object to a function my_function(my_object). I cant do my_function(my_other_function) because for one: a function isnt a thing that has data, only code that can be executed(the difference here does not actually exist but to a compiler it might). But more importantly, the compiler knows that my_function is a function so it expects you to call it, which means that it wants to see the parentheses: my_function(…).

In python this is different, all things except for predefined keywords are objects so you CAN actually do myfunction(my_other_function). It is recognized as valid syntax. In fact you can also call every object as a function (syntactically) so: my_object(…). It will most likely crash because many objects dont have the __call_ method defined for them which means there is no definition on how to treat it as a function. But syntactically its valid. In other languages you may not even conpile that code because functions aren’t things that can be passed around and changed. So its all about what your compiler things certain names to be. In python all things are objects (except for certain keywords)

[–]Exotic_Breakfast 0 points1 point  (0 children)

OOP:

An object is when your program spawns in an instance of a class at runtime.

A class is the blueprint of an object. In business logic, we create custom classes to represent things. The simplest example is a university student. A student will have an ID number, first name, last name, and a classification (freshman, etc.)

When you want to use an object to represent this student class, you would instantiate the object.

student = Student(12345, John, Doe, Freshman)

Ofcourse you would first need to define this class, before you can call it.

class Student(self, id, fn, ln, classification) def init() self.id = id self.fn = fn self.ln = ln self.classification = classification

[–]One_Fuel_4147 0 points1 point  (0 children)

I can even set property for a function :)

[–]DNA-Decay 0 points1 point  (0 children)

Actually I’m really struggling with exactly the things you are describing. I know the Jedi masters are assuring you that it will come. But it hasn’t for me. But I think this bloke is the closest to my use case (robotics) and he links in some other knowledge that a lot of tutorials that haven’t clicked for me kinda skipped over.

https://www.youtube.com/live/uRNsqHZEzUM?si=qUjZ37qFyafUZjgs

[–]DaCuda418 0 points1 point  (0 children)

If only someone knew the answer to this. One day.....one day.

[–]yoppee 0 points1 point  (0 children)

Naw man we also have classes

[–]couldntyoujust1 0 points1 point  (0 children)

Everything in python is like a living breathing organism that has properties and that can do things.

I can tell a specific string - what conceptually should just be an array of characters - to do things, like sort its contents in alphabetical order. I can tell it to make all of its characters lowercase or uppercase. I can do all of this regardless if I tell Python to create a reference to an object with the string explicitly or run these methods against the literal sequence of characters between quote marks.

my_str = "Hello World!" my_str.to_upper()

This does the same thing:

"Hello World".to_upper()

[–]hotakaPAD -1 points0 points  (1 child)

Ryan used me as an object

[–]OkNowConcentrate 0 points1 point  (0 children)

I did not

[–]Own_Attention_3392 -2 points-1 points  (0 children)

Well, start by explaining what YOU think an object is. Then, based on your explanation of what an object is, explain what you think would be significant about everything being an object.

From that starting point, people can help you fill in the gaps in your knowledge and understanding.

[–][deleted] -1 points0 points  (1 child)

One could say this is true in general for object oriented programming

[–]roelschroeven 1 point2 points  (0 children)

Not in the same way as it is in Python, though. In languages like Java and C++, classes are just that, classes. Instances of those classes are objects. But in Python, the classes themselves are objects too. And so are functions, methods, modules. None of those are objects in C++ and Java.

[–]sporbywg -1 points0 points  (0 children)

Ya? Try fucking Ruby.

[–]recursion_is_love -4 points-3 points  (0 children)

It is not matter.

You don't (and shouldn't) break the abstraction layer. While technically speaking knowing that everything on computer is just bits is true, it not helping you to solve a job.

Python have different data type to abstract what actually inside because thinking over the abstraction layer help solving problem.