JohnSmith
Posts: 9
Joined: Sat Dec 15, 2012 3:24 pm

Python absolute beginner

Sat Dec 15, 2012 9:41 pm

Hello,
Does anyone know where I can start to learn python? I have absolute no expierence with any programming language.

MattCook
Posts: 16
Joined: Tue Feb 21, 2012 1:46 pm
Location: S. Manchester

Re: Python absolute beginner

Sat Dec 15, 2012 11:16 pm

Hi JohnSmith,

The good news is, you have loads of choice ! The bad news is, exactly the same ... :?

There are two versions of Python shipped with the Pi - 2.7.3 and 3.2.3 These are pretty similar, but do have some differences, so choice number 1 is: which version to choose to learn with ? Version 3 is newer, and will continue being developed, while version 2 is older, and so has a larger base of sample code available. I can't see myself writing code that depends upon external code that is only compatible with version 2, so I have opted to focus on 3. They are very similar in most respects anyway, so skills picked up learning one will transfer very quickly to the other version.

There is a package called Pygame, which adds functionality which is handy for games types of programs - moving shapes around the screen, checking for collisions, or key presses, that sort of thing. This is currently easy to set up for version 2, and rather more long-winded (and still really beta-stage software) for version 3. If you want as easy a start as possible, and want to do games stuff, then 2 might be better for you. Google will of course help you if you want Pygame for version 3. More hassle to set up, but once installed, it's there...

So, now you have decided which version you will be learning, you can choose a tutorial. There are many books which can be read free on the web, as well as a tutorial in the python documentation. More are available for 2 than 3, but good ones are available for both. It is impossible to make a recommendation specifically for you though. I suggest looking at a few, and seeing which 'feels' best for you. Some to look at are:

Dive in to Python (available for both 2 and 3)
Invent your own computer games with Python (only 3 I think)
Learn Python the hard way (only 2 I believe)
How to think like a computer scientist (both 2 and 3)

In the end I opted for a variant of the last one available via this link. It is not perfect for pi, as it has been tailored for a particular course, and assumes that you will be running the PyScripter IDE under windows. You won't. PyScripter is not available for Linux of any flavour. I use Geany instead (sudo apt-get install geany). This means that screenshots will not look identical, but there is no great problem there for me, so that is OK. You may prefer another choice.

The main advice would be to learn it by doing it. I use a browser in half the screen showing the book, and geany in the other half for me to program in. (Small side note here. On the pi, you can leave geany as the active window, but simply moving the mouse over the browser will enable you to use the wheel to scroll, without needing to keep clicking backwards and forwards. Nice.) Type lots of examples - even if they are trivial. You will make mistakes, and learn more from them than you would from just reading and thinking you have learned it. Do the exercises. Even if you know what the program will be. I have been coding (not Python) for donkey's years, and I am making silly mistakes in Python. Learning fast that way!

You will always get help from people here. The more specific the question, the better the help of course. If you want to know exactly how to set up geany, and use it to learn with, you can drop me a PM or post a question.

Good luck with whichever approach you decide. Look at the options, and pick what is best for you. Too many choices with no frame of reference to help you decide at this stage, but really, you can't make a wrong decision.

Matt

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Python absolute beginner

Sun Dec 16, 2012 7:25 am

I reckon Matt's just about covered it there, all I can add is to keep a notepad and pen handy. You could use a function 10 times today and not remember what to pass it tomorrow so take notes. Also a good idea to plan your program before coding, jot down what needs doing and in what order, will save you a lot of messing round later.

Dave.
Apple say... Monkey do !!

JohnSmith
Posts: 9
Joined: Sat Dec 15, 2012 3:24 pm

Re: Python absolute beginner

Sun Dec 16, 2012 1:10 pm

Thanks for the reply's guys,
After reading your post, I think its better if I start to learn python 3. :D But if I want to learn python with this method "inventwithpython" must I use geany for that or just IDLE 3 that was included in raspbian? And what are the advantages of using geany instead of IDLE?

MattCook
Posts: 16
Joined: Tue Feb 21, 2012 1:46 pm
Location: S. Manchester

Re: Python absolute beginner

Sun Dec 16, 2012 2:32 pm

Hi again.

There are no 'musts' anywhere here, just (too many) choices.

You can simply use a text editor, save the files with a .py extension, and from a terminal type 'python3 name.py' to run it. Advantage: you can use a text editor that you are already familiar with. Disadvantage: most text editors know nothing of python syntax, and so won't help you trap typos etc.

You can use IDLE3 (for python 3). To write a program, select File/New Window from the Python Shell, and type in your code. F5 will save and run the program. Advantages: Common interface to all systems, so working on Windows or OS X or Linux will be just the same; Knows the syntax, so will help with indentation, highlighting etc. Disadvantage: Fairly basic editor.
Video of IDLE 3 editor in use.

You can use another Integrated Development Environment (IDE). There are many - geany is just one. Advantages: Better editors allow for code blocks to be expanded/collapsed for readability (think folders/sub-folders on a file manager); Autocompletion available (if you want it); May have additional useful features for you - varying for different IDEs. Disadvantages: Something else running, so can be a little slow; Another interface to learn until you get to grips with it.
Video of Geany using Python 2 on a pi - skip to 1:30 to see it in action.

I have linked to a couple of videos (you won't see these on the pi unless you have something that enables flash to work, so use your main computer), to give you some indication of the differences. IDLE is probably perfectly fine for learning with. An IDE becomes nicer as programs get bigger.

Yer pays yer money and yer takes yer choice ! They all cost the same ;)

Matt

antiloquax
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
Contact: Website

Re: Python absolute beginner

Wed Dec 19, 2012 6:03 pm

I've put links to some tutorials on this python section of this web page.

raspberrypy.co

There are also some videos and other tutorials on my blog.

teampython

My take on the Python 3 & pygame thing is to use Python 3.1.4, which works nicely with pygame. The arch sd card image (see the blog for details) has this pre-installed :)

User avatar
Rubber131186
Posts: 8
Joined: Wed Dec 19, 2012 4:22 pm
Location: Somerset, England

Re: Python absolute beginner

Wed Dec 19, 2012 8:26 pm

Create a Python game for the Raspberry Pi

I found this little guide very helpful and goes into enough detail.

http://www.pcpro.co.uk/features/376867/ ... spberry-pi

LetsLearnCoding
Posts: 2
Joined: Thu Jun 11, 2020 4:09 pm

Re: Python absolute beginner

Thu Jun 11, 2020 4:11 pm

Hi

This course has helped me tremendously at the start of my career! After that, it was a matter of practice to perfect my skills!

https://www.freecodecamp.org/forum/t/be ... n/238300/5

Return to “Python”