Learn Python for Physics: Introduction vs Scientific Programming

In summary, I would recommend starting with a book like "Think Python" and then moving onto another book like "A Primer on Scientific Programming with Python" if you want to get into scientific programming.
  • #1
Headacheguy
46
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
  • #2
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:
  • #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
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
You should learn some C, if only because using SciPy you can inline C in your program, which is pretty nice :)
 

FAQ: Learn Python for Physics: Introduction vs Scientific Programming

1. What is the difference between "Introduction to Python" and "Scientific Programming"?

The main difference between these two courses is their focus. "Introduction to Python" typically covers the basics of the language such as syntax, data types, and control structures, while "Scientific Programming" focuses on applying Python to solve problems in scientific fields like physics.

2. Can I learn Python for physics even if I have no prior programming experience?

Yes, you can still learn Python for physics even if you have no previous programming experience. It may take some extra time and effort to understand the fundamentals of programming, but with dedication and practice, you can master both Python and physics concepts.

3. Is Python a good language for scientific programming?

Yes, Python is a great language for scientific programming. It has a wide range of libraries and tools that are specifically designed for scientific computations and data analysis. Its syntax is also easy to learn and read, making it a popular choice among scientists and researchers.

4. What are the benefits of learning Python for physics?

Learning Python for physics has several benefits. First, it allows you to automate repetitive tasks and perform complex calculations quickly and accurately. It also provides access to a vast array of libraries and tools for data analysis and visualization. Additionally, Python is a versatile language that can be used for a wide range of applications in physics, making it a valuable skill to have in the scientific community.

5. Are there any recommended resources for learning Python for physics?

There are many resources available for learning Python for physics, including online courses, textbooks, and tutorial websites. Some popular resources include "A Student's Guide to Python for Physical Modeling" by Jesse M. Kinder and Philip Nelson, "Python for Data Analysis" by Wes McKinney, and online courses on platforms like Coursera and edX.

Similar threads

Replies
10
Views
2K
Replies
2
Views
2K
Replies
13
Views
2K
Replies
1
Views
972
Replies
16
Views
2K
Replies
13
Views
2K
Replies
4
Views
1K
Back
Top