Jake Yoon
Jake Yoon

Reputation: 138

Is Python a functional programming language or an object oriented language?

According to tutorialspoint.com, Python is a functional programming language. "Some of the popular functional programming languages include: Lisp, Python, Erlang, Haskell, Clojure, etc."

https://www.tutorialspoint.com/functional_programming/functional_programming_introduction.htm

But other sources say Python is an object-oriented programming language (you can create objects in Python).

So is Python both? If so, if you're trying to program something that requires lots of mathematical computations, would Python still be a good choice (Since functional languages have concurrency, better syntax for math, and higher-level functions)?

Upvotes: 7

Views: 14488

Answers (1)

Masklinn
Masklinn

Reputation: 42247

Python, like many others, is a multi-paradigm language. You can use it as a fairly strictly imperative language, you can use it in a more object-oriented way, and you can use it in a more functional way. One important thing to note though is that functional is generally contrasted with imperative, object-oriented tends to exist at a different level and can be "layered over" a more imperative or a more functional core.

However Python is largely an imperative and object oriented language: much of the builtins and standard library are really built around classes and objects, and it doesn't encourage the sort of thinking which functional languages generally drive the user to.

In fact going through the (fairly terrible) list the article you link to provides, Python lands on the OOP side of more or less all of them:

  • it doesn't use immutable data much (it's not really possible to define immutable types in pure python, most of the collections are mutable, and the ones which are not are not designed for functional updates)
  • its execution model is very imperative
  • it has limited support for parallel programming
  • its functions very much do have side-effects
  • flow control is absolutely not done using function calls
  • it's not a language which encourages recursion
  • execution order is very relevant and quite strictly defined

Then again, much of the article is nonsense. If that is typical of that site, I'd recommend using something else.

If so, if you're trying to program something very mathematical and computational, would Python still be a good choice

Well Python is a pretty slow language in and of itself, but at the same time it has a very large and strong ecosystem of scientific libraries. It's probably not the premier language for abstract mathematics (it's rather bad at symbolic manipulation) but it tends to be a relatively good glue or prototyping tool.

As functional languages are more suitable for mathematical stuff

Not necessarily. But not knowing what you actually mean by "mathematical stuff" it's hard to judge. Do you mean symbolic manipulations? Statistics? Hard computations? Something else entirely?

Upvotes: 23

Related Questions