Learning Python

  • #1
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?
 

Answers and Replies

  • #2
282
0
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 [Broken]

From that discussion:

http://openbookproject.net//thinkCSpy/ [Broken]

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:
  • #3
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()
{
cout << "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
cout << 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!
>>
 
  • #4
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
 
  • #5
6,817
16
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.
 
  • #6
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.
 
  • #7
202
1
You should learn some C, if only because using SciPy you can inline C in your program, which is pretty nice :)
 

Related Threads on Learning Python

  • Last Post
Replies
6
Views
2K
  • Last Post
Replies
1
Views
918
Replies
4
Views
768
  • Last Post
Replies
2
Views
2K
Replies
4
Views
2K
  • Last Post
Replies
12
Views
2K
  • Last Post
Replies
5
Views
2K
  • Last Post
Replies
5
Views
2K
  • Last Post
Replies
7
Views
3K
  • Last Post
Replies
10
Views
3K
Top