Python For N00bz ;)

zaka100

W͂Oͨ̍̍̒̈́͛̕
Messages
762
Location
Birmingham, UK
Learning Python For Beginners Lesson 1
(learn to program the hard way the easy way)​

Hi, guys. Welcome to my tutorial on Learning Python For Beginners! In the tutorial, I will attempt to teach any non-programmers the basics of python and programming. Just to make this clear, I will be teaching python 3.x.x, not 2.x.x.

Preface:
Zzzzzz..... I'm not going to write a boring, long preface. For me, it just puts me off the whole book/tutorial.

Requirements:
- A computer
- A brain
- Common sense
- A pair of hands
- Python 3 installed on your computer
- Basic knowledge on computers and how they work (if you don't know what deleting System32 does, this tutorial is not for you)
- A Basic understanding on algorithms (I will explain further on how to get a better understanding on algorithms)

Understanding Algorithms:
If you don't know what an algorithm is or how they work, it is basically step-by-step instructions to do something (e.g: an algorithm to speak is: open your mouth, make a noise through your mouth). If you still don't understand or want to learn more, try using programs like 'Scratch' and 'Stencyl' which utilise basic box dragging and dropping mechanisms to make simple algorithms and behaviours in 2D games. Eh.

Installing python:

Windows:
Go to python.org and download any version of python 3.x.x, try downloading the latest version but any version will do. Don't download any ide, it is harder to learn using those. Just use the default python IDLE.

Ubuntu (idk about other distros):
Ubuntu has python 3 already installed.
To install the IDLE, go to the Ubuntu Software Center and search 'python 3 idle'. Download the latest idle version.

The Python IDLE:
Idle_image022.jpg


This is the python IDLE shell. It will act as the console screen for running your python code. To create a new file, do CTRL-N. To open a '*.py' file, do CTRL-O.
To run an opened python file, press F5.

Hello World:

Create a new file and paste the code:

Code:
print("Hello World!")

Run the code.

That's it! That is the hello world for python! Nothing else! Just print and 'Hello World' in speech marks and brackets! The print function is used to display text on the console - not like that takes much thinking.

Looking At Variables:

Have a look at the following code:

Code:
text = "I like cake"
print(text)

What do you think it does? If you thought it would print 'I like cake', then you are right!

A variable is when you assign a name to something. It is a bit like saying 'do your chores' instead of saying 'wash the dishes, clean your bedroom, mow the lawn...'.

What the code means is that in line 1 it is saying in line 1 that "by when i say 'text', I mean 'I like cake'.

There are three types of variables I would like to talk about, strings, ints (integers) and floats.

Strings:
A string is any sequence of characters (any utf-8 character) in speech marks (double or single). E.g:
Code:
"Example String"
"Example String 2 $)£!%^~"

Integers:
An integer is any whole number. It can be negative too. It doesn't have any speech marks. E.g:
Code:
138
-875

Floats:
A float is basically an integer but with a decimal point. E.g:
Code:
492.85
-42.967

The '+' sign:
For strings, the '+' sign is used to join two strings together into one.
E.g:
Code:
string1 = "Hello "
string2 = "User"
joined = string1+string2

For integers and floats, the '+' sign is used to 'add' numbers together. '-' means minus, '/' means divide, '*' means multiply, '**' means multiply to the 'power'.
E.g:
Code:
int = 2+4 # The answer is 6

int1 = 5
int2 = 9
final_int = int1*int2 # The answer is 45


float = 2.5+4.2 # The answer is 6.7

float1 = 2.5
float2 = 2.0
final_float = float1+float2 # The answer is 5.0

Converting Variables:

Here is are some situations:
Code:
Situation 1:
number = 10+2.5 # You are expecting 'number' to be 12.5

Situation 2:
text = "My Age: "+5 # You are expecting 'text' to be 'My Age: 5'

Situation 3:
math = "5"+2.1 # You are expecting 'math' to be 7

Situation 1 will work however it is better to take my advise that I will tell later.
Situation 2 and 3 will not work. It will result in a 'TypeError' because you cannot add a string and int/float together. The python interpreter does not know if you want to add the variables together or to join them.

To fix this, you will have to convert the variables. You can convert variables to a string by doing 'str("Example String")', you can convert to an int by doing 'int(100)' and you can convert to a float by doing 'float(100.0)'.
E.g:
Code:
Before:
text = "5"+2

After:
number = int("5")+2


Before:
text = "My Age: "+5

After:
text = "My Age"+str(5)

Thanks for reading. Soon I will update my tutorial and add more :). Tell me what you think.
Zaka100
 
Last edited:
I'm actually interested in learning more about Python. I already know the basics but I think this definitely would've helped me if I hadn't. Looking forward to the next update.
 
You should talk about how specific functions relate to practical use in the real-world. Try to create a visual scenario, so talk about (eventually), at least in example, how a python script could go further than say, something developed using C++.

Other than that, good start OP!
 
It's very good that you want to teach people...but, maybe, firstly you should become an expert. At large, very nice way of presentation, but it looks like you don't have much experience. It's only my opinion and I don't want to harm anyone:)
 
Well I wouldn't say Im a noob myself, I don't really know all those professional coding practices because I'm self taught 15 year old and I find all that stuff boring. I find coding fun and as long as this tut teaches what its supposed to teach then I'm happy.

Im not disagreeing that I lack experience, if I look at this tut a few years later I'm probably gonna cringe
 
Last edited:
Well I wouldn't say Im a noob myself, I don't really know all those professional coding practices because I'm self taught 15 year old and I find all that stuff boring. I find coding fun and as long as this tut teaches what its supposed to teach then I'm happy.

Im not disagreeing that I lack experience, if I look at this tut a few years later I'm probably gonna cringe

Be careful with that. Getting into bad habits is easy, especially when teaching yourself. This is why I advocate the vetted tutorials (from places like CodeAcademy), as they follow industry standards, and other good habits/practices.
 
Back
Top Bottom