What does it mean that Python is an “object-oriented” language?


#1

Question

In the lesson description it says that Python is an object-oriented language. What does that mean?

Answer

The main goal of an object oriented language is to make code reusable – we do this through the use of classes and objects. If we want to design a new type of car, we can start with what they all have in common: wheels, seats, a frame. Now that we’ve determined what cars have in common, we can more easily implement any type of car we want by starting from that basic blueprint.

That’s a very basic explanation of classes, but you’ll dive into the details in later lessons and learn about how this approach to programming saves tons of time and effort, saving you from reinventing the wheel so often.


FAQ: Learn Python - Python Syntax - Hello World!
#2

While it is true that everything in Python is an object, Python can be used as a hybrid/functional language as well. Python has also entered the non-blocking (asynchronous) realm dominated by JavaScript as well with the async keyword. I mention this because the functional programming paradigm is at least (if not more) important in the world of multi-core (CPU) programming that continues to dominate. Languages that can easily leverage every core (Haskell, Erlang, Clojure, Go) will continue to dominate and influence their more imperative ancestors like Python. In short, saying “Python is an object-oriented language” is not the full story. It is also a functional language as well depending on how it is used.


#3

I feel like I need to learn a new language to understand people talking about languages! Is an object oriented language not functional? What are the elements being joined by a hybrid language? What is the “non-blocking (asynchronous) realm” and is it important to learn about it while/before completing the first objective of the first part of the first language I am learning (Python)? Where does one go to learn how to interpret and understand a comment like the one above? Will it all just come in time as I progress through the lessons or is there another course of study needed?


#4

Juggling many tasks at once is getting increasingly important, and even though this is getting “easier” and there may be more motivation to learn such things earlier… Still gotta start with learning how to do one thing at a time.

Some languages have cheap threads, allowing each task to have its own, so even though it may be doing blocking operations (waiting for some message maybe), they won’t stop other tasks.
Others give up control while waiting (asynchronous). This makes for more difficult code but the language might not have cheap threads, so they they share a thread instead.
Others yet may be limited in ways that makes it easier to reason about what happens, allowing out of order or parallel execution without the programmer having to say so.
Additionally, tasks need to communicate with each other or access shared resources, all without breaking each other, getting in each other’s way, or getting stuck waiting for each other to finish

As for object oriented, I think that’s… a separate topic from concurrency.
It’s a group of patterns/techniques. Not all apply to all object oriented languages. And yes, most descriptions of what it is are impossible to understand and miss the point. (Or perhaps that’s me misunderstanding, how would I tell, right)
I’d say object-oriented means that objects (values) are responsible for their own behaviour, allowing other code that isn’t familiar with a particular value-type to interact through those behaviours. For example, a list is iterable, it’s something the value itself knows how to do, you pretty much ask it “please provide your elements one at a time”


#5

Rather hard to say, because this very first lesson introduces some very imperative things, as contrasted to declarative and functional

Put it simple:

  • functional well yes you don’t really need to change a variable, or ask the computer to make the calculation instead of just writing the answer in the lines. Functional languages actually ask you not to do the above, and their complier knows that and reasons by itself ‘ehh that variable is never needed ever again after its first use, think I can ask the computer to discard it in the final machine-readable code’, or ‘lemme reason (*#%@ ahh yes by the theorems of some mathematicians these can run out of order’ (restrictions means easier proof/more properties).

  • object oriented an improvement over earlier imperative effort and usually implies imperative therefore. It’s a way of organizing and reasoning the logic of the program, such that the int you designated to represent the number of your anniversaries won’t ever be changed by some non-sense arithmetics - the complier won’t allow you to do that since you told it before ‘this thingy ain’t normal integer, don’t accept multiplications’. And say integers and characters are both represented as 0s and 1s, but you only want .upper() (which calculates a new 01-representation) to be allowed to operate on characters. OOP is one disciplined approach to this need.


#6

I’m just curious about what kind of integer can’t be multiplied. As I leaned it, an Integer is just a ‘whole number’, but not a fraction and not a number with a decimal point and more numbers to the right of it. So what kind of whole number cannot be multiplied?


#7

Although integer has its set of permissible operations, defined by language designers, not all arithmetic operations make sense in all use cases.

Consider ‘year AD’. Does multiplying a year with another year really make sense?Thus you’d define a Year, which is really just an integer, but has only Year*Num and Year+Year operations. This way nobody can get away with Year 1987*Year 2018, which looks like totally legal integer multiplication but is definitely a mistake.

In theory you can do arithmetic operations on arbitrary type - they are all zeros and ones and can be considered “numbers”.
You just don’t want to, and can live without the ability to calculate char+1. Even better, if the compiler would loudly complain when you ever tried to do that.


#8

Nope. You might as well be writing in sanskrit. I am a complete beginner to all forms of coding. “cheap threads” “blocking operations” “asynchronus” “parallel execution” I’m lost already. I’ve just learned to print Hello world. That’s all I know. Really.