Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

henry jefferson
henry jefferson
2,136 Points

What is an object?

Hi,

I'm trying to build a sort of mental picture of how the language works together. I read a little about the notion of 'first class objects' but I wanted to flesh it out a bit more.

My understanding is as follows: Everything is an object and in pretty much all cases objects have attributes and they have methods. for example, a string is an object, it has attributes such as it can be multiplied but not divided, it's not mutable, it's iterable. It has methods such as str.lower() Also, objects can be assigned to variables and passed into functions as arguments.

Is this correct? Dictionaries and lists objects or are they containers of objects? what is the difference between a class and an object? Is my definition of attributes correct? is not being mutable an attribute or is something like 'hair' = 'yellow' more of an attribute?

I'd be really grateful if someone could clearly explain the broad architecture behind pyhton.

Many Thanks,

Henry

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Keep in mind that objects are not limited to just the Python language. They are used in all sorts of programming languages as something called "OOP" or object-oriented programming. And yes, objects can be made of other objects.

Now, I don't generally just recommend that someone randomly switch tracks. And I'm not going to suggest that you switch to the PHP track, but I do highly recommend watching the first few parts of this series as it gives a brilliant explanation of OOP and why we want to use it.

https://teamtreehouse.com/library/objectoriented-php-basics-2/why-objectoriented-programming/what-is-objectoriented-programming

In fact, you'll likely as not do any coding in the first part of this as it is all about the concept of object oriented programming. Hope this helps! :sparkles:

henry jefferson
henry jefferson
2,136 Points

Thanks Jennifer, I just watched them. She made a good case! If you have a second would you be able to expand a little on the question in regards to the way python is constructed? I'm working through the class section in the py track and constructing classes is a good way of understanding OOP (as in the house analogy)

henry jefferson
henry jefferson
2,136 Points

I do!

is being mutable, iterable an attribute?

are tuples, lists and dictionaries objects or repositories for objects?

Thanks Jennifer

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Ok, I'll give it a go! As I understand it, lists and dictionaries are (although I'm still not totally sure on the tuples) are classes. And I'm also given to understand that these have read/write attributes which is what potentially makes them mutable/immutable.

But keep in mind that a list can contain a list. Here you have an object being stored by an object. And in fact, these are sort of considered special "container" objects and/or sequence types which is what allows us to iterate over them.

I found a couple of interesting pages in the python documentation:

Built in types:

https://docs.python.org/3.3/library/stdtypes.html#list

Classes:

https://docs.python.org/2/tutorial/classes.html

I sincerely hope this is accurate. It is possible though that I've misunderstood something. Hope this is helpful!

henry jefferson
henry jefferson
2,136 Points

awesome, thanks, Jennifer. I'll read through the python doc's and confirm what you've suggested.

Thanks again