7

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)?

8
  • 5
    Yes, Python can be used as both. Commented Sep 14, 2020 at 18:07
  • 8
    "Python is a multi-paradigm, dynamically typed, multipurpose programming language" (emphasis mine) - from the description of the Python tag Commented Sep 14, 2020 at 18:09
  • 4
    I really wouldn't consider Python a functional programming language. It has first-class functions, which allows you to use it as a functional programming language, and it borrows some nice features from functional programming languages, like list comprehensions, but it is fundamentally very imperative. Note, OOP lies on a different axis, really. Consider scala, which is very functional (although not purely), and yet, is also very OOP. Commented Sep 14, 2020 at 18:25
  • "If so, if you're trying to program something very mathematical and computational, would Python still be a good choice (As functional languages are more suitable for mathematical stuff)?" this is not a valid premise, I think, depending on what you mean by "mathematical stuff" and "computational". Do you mean things like numerical programming? Because you would either use a higher-level language designed for that, e.g. Matlab, or something close to the metal, e.g. C or fortran. Although note, numpy is a popular package for python that allows for fairly effective numeric programming in Python. Commented Sep 14, 2020 at 18:29
  • I think what you may mean is that mathematicians tend to like purely functional programming languages like Haskell and really like type theory and where the culture is often quite adjacent to pure/abstract mathematics, and terminology from category theory abounds. Commented Sep 14, 2020 at 18:34

1 Answer 1

24

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?

Sign up to request clarification or add additional context in comments.

2 Comments

my impression of tutorialspoint is that it isn't great for anything but the bare-bones basics, and even then, it can be wrong. It may have gotten better lately, but I seem to recall it would often promote various unidiomatic things in Python, at least.
I am trying to appy some of the oop that I know in java on python. Applying oop in a 100% fashion is so difficult

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.