Learn Python for Physics: Introduction vs Scientific Programming

Click For Summary

Discussion Overview

The discussion revolves around the best approach to learning Python for physics applications, specifically whether to start with an introductory Python book or a scientific programming book. Participants share their experiences and preferences, considering their backgrounds in programming and the relevance of different programming paradigms to physics computations and simulations.

Discussion Character

  • Debate/contested
  • Exploratory
  • Technical explanation

Main Points Raised

  • One participant suggests starting with an introductory book like "Think Python" for a foundational understanding, especially for someone with little programming experience.
  • Another participant argues for starting with C++, claiming it provides a better grasp of programming concepts before transitioning to Python, although they acknowledge Python's utility in scientific research.
  • A different participant shares their positive experience learning Python from "Beginning Python From Novice to Professional," emphasizing the importance of understanding different programming paradigms.
  • One participant expresses frustration with C++ due to its complexity and suggests that Python is more straightforward and easier to learn, indicating a preference for starting with Python.
  • Another participant mentions the advantage of learning some C for using SciPy, which allows for inlining C in Python programs.

Areas of Agreement / Disagreement

Participants express differing opinions on whether to start with Python or C++. There is no consensus on the best approach, as experiences and preferences vary widely.

Contextual Notes

Some participants highlight the challenges of learning programming concepts alongside complex syntax and memory management in C++, which may lead to frustration for beginners. The discussion reflects a range of experiences with different learning materials and programming paradigms.

Headacheguy
Messages
46
Reaction score
0
Is it better to start learning Python using a introduction to python book (Think Python) or a scientific programming book (e.g. A Primer on Scientific Programming with Python, 2009)? I have little to no programming experience.

I'd use python solely for physics computation/simulations. I was thinking of math in relation to physics, that is, learning the proof helps in understanding how to use math in solving physics problems. Is this also the case with scientific programming?
 
Technology news on Phys.org
I don't have any experiences with either book.
IMO you should always start with C++. It's just a personal view that it is better to attack the common programming stuff and then go to a more laid-back rapid development type programming language (Python can be quite weird to an experienced programmer at the first glance). I have seen people using Python for scientific research.

For me it was a lot easier to learn Python after having exposed to C++. It is very hard for me to explain why I came to this conclusion. I think it is because I can condense a huge C++ program into a much smaller Python program.

Someone else has recommended this site, and I second this

See discussion here:
http://stackoverflow.com/questions/17988/how-to-learn-python

From that discussion:

http://openbookproject.net//thinkCSpy/

PS:
You can always find Python books from local library / school library. DON'T EVER BUY A BOOK UNLESS YOU HAVE READ IT.
 
Last edited by a moderator:
I learned Python from a book entitled "Beginning Python From Novice to Professional" by a fellow with an interesting sense of humor named Magnus Lie Hetland. He is professor of algorithms at NTNU.

He builds all of the computer jargon from the ground up, explaining things in a way that the absolute can understand. I say this because at the time that I was reading his book I was an absolute beginner to the computer programming scene.

Warning! Long story ahead:
--------------------------------------------------------------------------------------
I had just finished my Bachelors in Physics, and my only background in programming came from a pseudo-numerical-analysis course that was offered by the math department in Matlab. You should know that there are different paradigms, or ways of thinking about programming, which forces you to adopt a certain way of thinking about solving a problem. Two of these paradigms that exist are "Scripting Languages" and "Object Oriented Languages". Matlab is a "Scripting Language", so this is the only school of thought that I had been trained in at the time. Python allows someone to do both "Scripting programming" and "Object Oriented programming".

I too was faced with the choice of, "c++" and by extension "c", or python? "c++" is also capable of doing both scripting and object oriented programming. However, it is also requires you to keep track of a lot more information. Using c++ you have to deal with memory management on top of learning a brand new "grammar" (or syntax, in computer lingo) and you need to do this on top of learning how to solve problems in programming.

The greatest danger with trying to learn programming from c++ with no computer programming experience is that you'll become frustrated with all of the details long before you are able to appreciate the beauty and the power that being able to program gives you.

An example of what I mean:

A simple "hello world" program in python:
print 'Hello world!'
Note also that this program above is saved in a file called, "hello.py"

Execution of the program on Linux:
>> ls
hello.py
>> python hello.py
Hello world!
>>

A quick variable creation and manipulation in python with comments:
x = 'Hello world!' #This defines a variable 'x' with the string "Hello world!"
print x
The above program also this program above is saved in a file called, "hello.py"

Execution of the program on Linux:
>> ls
hello.py
>> python hello.py
Hello world!
>>

A simple "hello world" program in c++:
#include <iostream>
using namespace std;

int main()
{
count << "Hello world!" << endl;
}
The above program is put into a file called "hello.cpp"

Execution of the program on Linux
>> ls
hello.cpp
>> g++ hello.cpp -o hello
>> ./hello
Hello world!
>>

A quick variable creation and manipulation in c with comments:
#include <iostream>
using namespace std;

int main()
{
char x[] = "Hello world!"; //This defines a variable "x" with an array of characters
count << x << endl; //"Hello world!"
}
The above program also this program above is saved in a file called, "hello.cpp"

Execution of the program on Linux:
>> ls
hello.cpp
>> g++ hello.cpp -o hello
>> ./hello
Hello world!
>>
 
In hindsight, I should've split the program and the execution boxes more.

I'm sorry if it makes your eyes bleed...

Sometimes repetition can be a bad thing... when you do it like I did. :P
 
Looking over both books, I think you are better off with the "Think Python" book. I think that trying to mix both CS knowledge and math simulation knowledge in the same book just makes things less clear and more confusing.
 
Thanks everyone.

@Jwxie: I tried C++ last before but got frustrated (as FourierFaux had described) on the details which I can't really understand. It could be that the book I use is not good. Nonetheless, Python is straightforward and easy to learn, at least for me, so I think I would start first with Python and reserve C++ for later.

So I guess I'll follow two-fish' advice and start with Think Python.
 
You should learn some C, if only because using SciPy you can inline C in your program, which is pretty nice :)
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 43 ·
2
Replies
43
Views
7K
Replies
6
Views
3K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 397 ·
14
Replies
397
Views
21K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K