Learn Python: Top Book Recommendations for Beginners

  • #1
robotkid786
21
7
I'm looking at a book called python crash course for beginners (eric mathes), does anyone have experience of using this book or any other book that you would recommend for learning python

if not that, is there a specific course you'd suggest that isn't in book form?

I'm completely new to programming if it helps. So i need a gameplan for learning it quite quickly for my undergrad studies
 
Physics news on Phys.org
  • #2
robotkid786 said:
I'm looking at a book called python crash course for beginners (eric mathes), does anyone have experience of using this book or any other book that you would recommend for learning python
I thought it was very poor. I can go into the reasons if you want.

I had done a lot of programming previously, so I used the book to get tips on syntax. It taught absolutely nothing about how to construct a program of any complexity. I fell back on my previous experience of procedural programming.

Note that, as I alluded to earlier, writing a program should be done in two steps:

a) Program design. You use neutral pseudo-code to design the structure and content of your program - based on the logic and algorithms demanded by your application.

b) Coding. You code your design using the appropriate language and syntax. In principle, the same design should apply independent of programming language.
 
  • Like
Likes vanhees71, Math100, robotkid786 and 1 other person
  • #3
okay, i can't say i fully understand what you mean by the two steps. like i say, i'm completely new. but i do know what it means when you say, syntax isn't explained.

how would you suggest i learn syntax, or even better; do you have any books recommendations for a novice which would help me learn

thanks
 
  • #4
PeroK said:
I had done a lot of programming previously, so I used the book to get tips on syntax.
Same here. I also was not impressed with the book but have used it for my transition from Tcl/Tk to Python.
 
  • Like
Likes vanhees71
  • #5
robotkid786 said:
okay, i can't say i fully understand what you mean by the two steps. like i say, i'm completely new. but i do know what it means when you say, syntax isn't explained.

how would you suggest i learn syntax, or even better; do you have any books recommendations for a novice which would help me learn

thanks
Let me give you an example. One of the tasks I set myself was to write a Sudoko solver (in Python). You can't just dive in an start cutting code. Well, actually, you can and most people do! First, I had to plan out exactly how my program was going to work. What data structures was it going to use? What logical algorithms was it going to use? Even what was its basic functionality: how were Sudoko puzzles going to be input? I had to design the Sudoko-solving algorithm before I could start programming.

Once you have all that on paper, then you go into the text editor and start writing Python code.

A simpler example would be a prime number generator; or a program that factors a (large) integer into prime factors. In this case, you want to get the mathematics sorted before you start programming. Otherwise you end up in a mess of different categories of error: logical, procedural, syntactical.

Hopefully, someone else can suggest a better resource for learning this stuff. The Mathes book isn't it, sadly.
 
  • Like
Likes PhDeezNutz, vanhees71 and robotkid786
  • #6
Is udemy a good resource?

In particular: "Computational Physics" Scientific programming with python

?
 
  • #7
robotkid786 said:
I'm looking at a book called python crash course for beginners (eric mathes), does anyone have experience of using this book or any other book that you would recommend for learning python

if not that, is there a specific course you'd suggest that isn't in book form?

I'm completely new to programming if it helps. So i need a gameplan for learning it quite quickly for my undergrad studies
I thought it was a nice introduction, but for physicists there are better introductions. One I really like is written by Pieter Spronck and available for free: "The Coder's Apprentice",

https://www.spronck.net/pythonbook/

If you want to dive straight into "scientific programming", the book by Christian Hill ("Learning Scientific Programming with Python") is good.
 
  • Informative
Likes berkeman
  • #8
You said you didn't understand what was meant by a plan in pseudo-code, (the first step as mentioned above) so here's an example.

You have to write a program where students log in, retrieve a random maths question from a database, answer it, get it marked, retrieve another random question, repeat as above until five have been answered, sign out.

So let's look at the initial steps (rather than do an entire program's pseudo-code, as my partner has just placed a glass of wine in from of me).

Pseudo - first attempt

login
fetch first question
enter your answer
mark it
fetch second question
enter your answer
mark it
......
rate student performance
log outPseudo - second attempt

Log in
...enter username
...enter password
fetch first question
...generate random number
...retrieve that question
...display on screen
mark answer
...store score
fetch second question
enter your answer
mark it
......
rate student performance
log outPseudo third attempt.

Login
...enter username
...search database for username and the password
...enter password
...check the password
...verify real user
fetch first question
... generate random number
...verify number within question range
retrieve that question (how?)
display on screen
...mark answer (how?)
...store score (how?)
fetch second question
enter your answer
mark it
...
rate student performance
...think of some sort of rating system to use
log out

As you can see the steps are laid out well before you write any code (and only some steps are shown above, as I think you have realised already). And you can start work on the program by just writing the tiny bits above and testing each part before moving on to write the next bit. And the big bonus - you can start writing the program, and gain assessment marks, without finishing the program if you work this way! And you can do this without finishing the pseudo code for every single step either, or even knowing every step (and not knowing every step is totally normal). AND the above pseudo code is correct whatever language you write the program with!You also say you are struggling to learn programming. The first programming language you learn is always the hardest. Because you know nothing about programming when you start. The second language is always easier, the third one easier still. And it (almost but not quite) doesn't matter which language you start with for this to be true. Then you might find you prefer one language to another for some reason, and stick with it. Python is supposed to be easier to learn than others. I haven't tried Python, but code samples do look familiar to what I see in other languages, with a few differences in syntax. But I know if I had to learn it, I could. Syntax is simply the format / grammar you use to write things.

When I first took up computing, I had missed the first three weeks of the course, and panicked in my first programming lesson as it started with here's a simple program to write (simpler than the above example). So I wrote down the steps in the style that I've shown above, while listening to the others typing away, and everyone swearing when it all went wrong, then started on my program. I knew I needed some sort of plan to get going, and as a lecturer, I guessed it would be worth some marks. Strangely, I finished before the rest of the group, who didn't take the above approach and just started typing code with no plan. And got a surprisingly high mark as well. Later, we were told about writing a plan in pseudo code. I think it was deliberately taught later to let the class see the problem of diving straight in without thinking. In more complex programs, you split it up into big blocks, then smaller blocks, then write pseudo code for each small block. And you can start on block one while still wondering about block ten's steps.

Hope this helps.

PS I am struggling with the indented extra steps, but you get the idea anyway
 
Last edited:
  • Like
Likes robotkid786

Similar threads

  • Science and Math Textbooks
Replies
4
Views
827
  • Science and Math Textbooks
Replies
2
Views
376
Replies
21
Views
8K
  • STEM Academic Advising
Replies
10
Views
1K
  • Science and Math Textbooks
Replies
6
Views
1K
  • Science and Math Textbooks
Replies
14
Views
3K
Replies
1
Views
2K
  • Science and Math Textbooks
Replies
4
Views
1K
  • Science and Math Textbooks
Replies
9
Views
376
  • Science and Math Textbooks
Replies
6
Views
2K
Back
Top