Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Learn Python?

  1. Jan 20, 2009 #1
    Hello, I have recently become interested in computational physics. I know a good deal of Mathematica. Recently I have heard great things about Python. My questions are:
    1) How useful is Python in computation?
    2) Would there be a better program to learn instead of Python for computation?
    Any additional comments would be appreciated.
  2. jcsd
  3. Jan 20, 2009 #2
    Last edited by a moderator: May 3, 2017
  4. Jan 20, 2009 #3


    User Avatar
    Science Advisor
    Gold Member

    If would have to pick "a couple" of languages to work with python would be one of them.
  5. Jan 20, 2009 #4
    Can you name the other ones?

    Also, can someone tell me:
    1)Two or more benefits of Python over Mathematica
    2)Two or more disadvantages of Python over Mathematica
  6. Jan 20, 2009 #5
    Personally speaking, I'd concentrate on Python and C/C++.

    *: Speed. CPython, the standard distribution of Python that you can download from python.org, is built upon C. Hence modules like Numpy and Scipy have been able to produce code that is in many cases significantly faster than equivalent Mathematica code.

    *: Python is an actual programming language. Mathematica, for all its wonderful uses, really isn't a serious language. Object orientation, for instance, is natural and easy to use in Python; although OOP is possible in Mathematica, it's ugly and cumbersome in an ungodly way.

    *: Python is a much more powerful language.

    *: It's free.

    *: It's more popular than Mathematica.

    *: It's got a much, much wider focus. For instance, Python will handle all of the numerical work Mathematica can do but can also do nifty, network-focused things with your data once it's been obtained. This is pretty much impossible with Mathematica.

    *: Well, Mathematica's real strength is in symbolic computation. To the best of my knowledge, Python can't do symbolic computation at all.

    *: Plotting in Python is poor in comparison to Mathematica, especially to version 7.0.
  7. Jan 21, 2009 #6


    User Avatar
    Science Advisor
    Gold Member

    Thinking about tools which enable to carry out "research tasks" as effectively as possible with a wide range of applicability (thinking about code performance, "usability" of the resulting code and development time) would pick a medium level language like C++, then Python which is actually kind of "in between" due to its performance imho and then Mathematica [scripting wise that is] (followed closely by Matlab, but its necessity is shadowed a bit by Python with scipy and works, although it's very easy to pick up). After those would pick good old Perl for some raw data processing, but most tasks do with Perl can be done nicely with Python.
  8. Jan 21, 2009 #7
    Here's a yet another reason to learn Python! Check the open source tool Sage http://www.sagemath.org/
    It is a python-based tool that integrates various (powerful) open source tools for numerical computations, statistics, symbolic computations, number theory, algebra(as diverse as group theory, linear algebra, representation theory, commutative algebra, and algebraic geometry), ...

    The integration of these tools under Python is exceptional in my opinion! There's a very useful "notebook" a la Mathematica! But much more powerful I'd say!

    It got not only great plotting capabilities, but also interactive ones, including Java 3D, take a look at http://wiki.sagemath.org/interact
  9. Jan 22, 2009 #8
    Is there a reason why I would learn Python over Fortran?
  10. Jan 22, 2009 #9
    Put it this way. In the two or three days you've spent asking other people's opinions, you could already have learned a sizeable and useful amount of Python.
  11. Jan 22, 2009 #10
    Oh good sir, who says I haven't been learning python? Not me.
  12. Jan 22, 2009 #11
    Neither did I. It was intended as a comparison with Fortran in the sense that in the few days you've been learning Python you've probably learned far more than you could have if you'd chosen Fortran.
  13. Jan 22, 2009 #12
    How about mathlab vs phython,which one is the best for a physics major?
  14. Jan 22, 2009 #13


    User Avatar
    Science Advisor
    Gold Member

    You'll get a whole lot more done :wink: . Comparing languages and "stating" what is needed is always a bit arbitrary (at best), but in "general terms" when learning to do things and so forth Fortran isn't quite as useful as Python (unless everything in your field is written in Fortran for some reason or something similar). Fortran has its uses and Python its own, unless you have something in mind where you especially need something Fortran does very well Python is an animal would recommend. Not to downplay good old Fortran, I still need it :biggrin: .
  15. Jan 22, 2009 #14
  16. Jan 22, 2009 #15


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    matlab, maple, mathematica, etc... are all very good for symbolic and numerical calculations and for visualization (thanks to a dazzling array of specialized functions).

    Python is more of a general purpose language... with a lot of useful functions imported through libraries and modules... and it's free and open source. For physics, there is this useful library http://vpython.org/

    Note that Python (via the optimized numerical linear algebra library NumPy) has many Matlab-like functions and syntax.

    If I were you, I'd learn both.

    (One thing Python can do (that many other languages can't do as easily) is
    interact with other programs... I've written Python (and Perl) programs that write Maple code... then a script can start Maple and execute it. If needed, Python can parse the output of the Maple program and do something else with it... e.g. send post-processed data to another program [like gnuplot].)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook