Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

|☣| Terror |☣| Huge Python guide - Start your Python adventure - The power of python!

[Image: cIIZR.png]

I will be adding new chapters daily so keep updated!
Apologies due to some images being a link, we're only allowed to include 15 images maximum which sucks :/

This guide will contain the following chapters;
  • Downloading / Installing Python.
  • Getting used to the GUI.
  • Basic output on screen.
  • Basic Math in python.
  • Using variables.
  • Functions.
  • Strings.
  • Some more Strings.
  • Raw input.
  • Comment out a line.
  • New line.
  • First piece of code!.
  • py2exe.

Chapter 1 - Installing Python..

In this chapter you will be explained on how to Install python correctly, ready to use!

First of you want to visit http://python.org when you're on the website you can see a download link in the navigation tab, go ahead and click it.

[img]http://static.afbeeldinguploaden.nl/1303/31719/Mksfe.png[/img]

Now you want to locate the download path, go to the section shown below and install one of the packages depending on your OS, make sure you download the latest version for better features.

[img]http://static.afbeeldinguploaden.nl/1303/31720/sWMrxqPc.png[/img]

Now what you want to do is let it finish downloading, once downloaded proceed to the next step..

[img]http://static.afbeeldinguploaden.nl/1303/31721/Bpr1WVI.png[/img]

Okay so now you have the installer downloaded, now open it and finish the steps, here you have the choice to download it on the user you're currently on, or to download it on every user on your computer.

[img]http://static.afbeeldinguploaden.nl/1303/31722/AouUIL3.png[/img]

Now here you want to choose a directory where python will be installed in, once you have selected the directory proceed..

[img]http://static.afbeeldinguploaden.nl/1303/31723/Lp0N.png[/img]

Here you can select a customized setup, i do recommend that you keep these as default and just hit next..

[img]http://static.afbeeldinguploaden.nl/1303/31724/deu.png[/img]

Now the installation loading bar will pop up, let it install..

[img]http://static.afbeeldinguploaden.nl/1303/31725/5iDw9G.png[/img]

Once you have successfully installed python, hit finish..

[img]http://static.afbeeldinguploaden.nl/1303/31726/jfsR.png[/img]

Now go to your start menu and type in the search box "Python" or simply go to the directory where you installed python and open "IDLE"..

[img]http://static.afbeeldinguploaden.nl/1303/31727/05gNiB8O.png[/img]

You have now successfully installed python on your desktop and can now proceed with the real work!


Chapter 2 - Getting used to the GUI..

Okay now that we fully installed python and opened the GUI we should be on this window..

[img]http://static.afbeeldinguploaden.nl/1303/31728/pwz.png[/img]

Now i will be going over the most important tool tabs that are used the most whilst coding in python.

First of we have our File tab, in this tab we can Open;Save;Print;Close or open a new fresh window (blank python file)

[img]http://static.afbeeldinguploaden.nl/1303/31729/rMxw.png[/img]

Now next to the file tab we have the "Edit" Tab, here you can reverse a change you made or recover it, You also have a find engine and a Copy;Past;Cut option.. This is pretty basic and common sense so i shouldn't to go deeper in this tab.

[img]http://static.afbeeldinguploaden.nl/1303/31730/8jOUo.png[/img]

Now the last important tab we will be using is the "Run" tab, here we can Run our Module (script)..

[img]http://static.afbeeldinguploaden.nl/1303/31731/nlgyv8.png[/img]

We can also open a python shell, Now what exactly is a python shell? A python shell executes codes directly when you hit enter, example;

[img]http://static.afbeeldinguploaden.nl/1303/31732/q89.png[/img]

What we basically did here is assign the value "1" to our variable Y & X , now when we use a simple math function "+" and input y + x it will see this as 1 + 1 since we assigned the value "1" to "x" & "y" and return with the answer "2".



Chapter 3 - Basic output on screen..

Okay guys so now let's get to some basic coding, what we will be going over in this chapter is how to display an output on your screen such as a message saying "Hey, how are you?"..
Now go ahead and open up A fresh new python module (Not your python shell)

We have different ways of printing an output, it really depends whether you want the user to input something or to just display a message or display a message depending on the answer of the client user.

Let's start..

3.a Print

The print command can be used by typing;
Code
print "Hey, how are you?"
Now when you hit F5 (shortkey for "Run Module) it should show the message you have put inside the double quotes, in this case; Hello, how are you?.. this can used anywhere to output a message on your program you create.

We will be coming back on more advanced print methods but for now i will keep this basic and make sure you can follow up before it gets any more complicated.


Chapter 4 - Basic Math in Python..

In this chapter you will be doing some basic Math that you learned in school, the reason why i'm going over this, is because math can be very useful in Python.. Okay so first of go ahead and open your Python "SHELL" , yes yes time to work with the shell.
You can open the Python shell by following the image below..

http://static.afbeeldinguploaden.nl/1303...sX28el.png

When you have the shell open it should look like this;

http://static.afbeeldinguploaden.nl/1303...JfzKBj.png

Now you can go ahead and type the following math functions;

  • 1+15
    Hit enter and you should see 16
  • 20-9
    Hit enter and you should see 11
  • 2*10
    Hit enter and you should see 20
  • 10/2
    Hit enter and you should see 5

http://static.afbeeldinguploaden.nl/1303...U465gJ.png

Ok so these azre very basic math functions, now that you understand that math can be used in Python we can move on to the next chapter, i recommend you play around with these math functions and we will becoming back on Math later on.

Chapter 5 - Variables..

A variable could be seen as a place holder where we assign a value to, we will keep this basic for now so let's get started..

Go ahead and open your python shell and type in;
Code
guide = 10
guide2 = 15

Now let me explain these lines, "Guide" is our variable name, "=" the equal sign obviously orders python to assign or variable name to "10" which is our value.

Now go ahead and type the following;
Code
guide + guide2
Now hit enter and the responds should be; 25

http://static.afbeeldinguploaden.nl/1303.../9OI3F.png

For those who don't get it yet, We assigned our variable "guide" to the value "10" and then we assigned our variable "guide2" to the value 15, now when we do guide + guide2 it basically see these 2 variables as 10 & 15.

You might be asking yourself, this is fucking useless well it is for now but when we will be getting deeper into coding you will see that variables are actually very useful..


Chapter 5.b - Allow a user to assign a value to Variables..

Now we can also allow a user to assign a value to a variable, this is also very useful in situations where we don't know what the variable's value will be.

Open up your python shell again and type in the following;
Code
test = input("What's your age? ");
Now a message should pop up, type your age in and press enter, you have now successfully assigned a value to variable "test".
Now you can type in for example;
Code
test + 15
It should do; 15 + the number you filled in as anwser. See picture below;

http://static.afbeeldinguploaden.nl/1303...pbu5TP.png


Chapter 6 - Basic functions..

A functions is pretty much a sort of build in program in python.
What you should know is when you wish to use functions you can import modules, for example our time module, this would me done by using "import" a module is basically holds certain functions that can be used by us once imported.
Now Go ahead open a python window NOT your python shell.
Once you have this opened it's time to write a small code.

Remember when we used our print function? well , we will now use this in our small app.

Type in the following;
Code
import time
print "Hello Bob i'm Tommy!"
time.sleep(5)
print "Hey there Tommy!"

Okay so line 1; We imported our time module which contains our time functions.
line 2: We used the print function to print something on the screen.
line 3: we used a time function, "time" tells python it's in the module "time" ".sleep" tells python we want the function sleep which will create a x amount of seconds pause. the seconds can be put betwean the ( ) behind sleep which is in this case 5 seconds.
line 4: Once again our basic print function.


http://static.afbeeldinguploaden.nl/1303...sNYPir.png

Now when you have that typed you can go ahead and press F5 (To run it) or you can also click "Run" in the toolbar and select "Run Module (F5)".

http://static.afbeeldinguploaden.nl/1303/31855/eXfT.png

Now it will ask you to save the file, do this.

http://static.afbeeldinguploaden.nl/1303.../QkuJc.png

Now it asks you where you wish to save it, select a location (I recommend creating a separate folder for your python projects.)

http://static.afbeeldinguploaden.nl/1303...zkEgqv.png

Now when you saved it it will run your little script like this;

http://static.afbeeldinguploaden.nl/1303...MnlTmq.png

There is a pause between both sentences which you can obviously not see on the picture..

Now some functions are pretty long to always type so what you can do is assign a function to a variables you want, yes haha you remember those right? This is the reason why i go over that stuff first so we will be using them all later on.

Go ahead and go back to your python file and erase it.
What you want to do now is import the module, type in your variable name followed by an equal sign and then the function name, Print function and the time function and last but not least another print.
Code
import time
tutorial = time.sleep
print "Hey there!"
tutorial(5)
print "yo sup!"

Now let's explain these lines;
line 1: We imported our module time
line 2: we assigned our function "sleep" to a variable which is "tutorial" in this case
line 3: We used the basic print function.
line 4: we used our function which was assigned to our variable "tutorial" so time.sleep is now seen as "tutorial" followed by (5) which is our seconds.
line 5: once again another basic print function.

http://static.afbeeldinguploaden.nl/1303/31859/Z57.png

Now when you run this again by pressing F5 it will come up the same as it did before.


Chapter 7 -Basic strings..

If you're already familiar with these you might of noticed we have already used these, for those who don't, will understand this now.

Strings are basically a bunch of words that we used like in our print command,
print "Hey Bob!" / Then Hey boy would be a string.

Now in a string you should know that this character "\" is an escape character, and when double quotes can be, and cannot be used.
Let's say we want to print out; print 'It's true, he's a liar'
Now i want you to type this in the python shell and look at the result.

http://static.afbeeldinguploaden.nl/1303.../OFDGI.png

That's right, we get an error called, Syntax error: invalid Syntax.
The REASON why I let you get this error, is because you can learn from errors, Reading your errors and understanding him will help you ALLOT in the near future.

Now let's see how we can solve this!
So we types; print 'It's true, he's a liar' Now as i said before there is something called an escape character.
This character can be used to trick python into reading the line in a different way.

We can do this by typing the following: print 'It\'s true, he\'s a liar'
Now go ahead and type that in your python shell and hit ENTER.

http://static.afbeeldinguploaden.nl/1303/31893/gsvm.png

It perfectly works! What python basically did is go over the line and see the first single quote as the opening , the single got of " It's " as a regular character in the string , same for the single quote in " He's " and after that the Single quote on the end as a closing of the string.

You may have also noticed to color change, these colors can also help you! That's why each time you save a python file you should at .py behind the name you save it as.

Another way to solve this problem is to use double quotes and single quotes in a certain way.

print "It's true, he's a liar"

Now Python will see the double quote as the opening , the single quotes as a part of the string and the last double quote as the closing one.


http://static.afbeeldinguploaden.nl/1303.../FDP1E.png

Chapter 8 -First piece of coding!

Now we can use strings in many different ways, Let's say we want to put 2 strings together by using a piece of code, this can be used for first names and last names when the user inputs them or numbers , ect.

Let's first try with ages, open a new python module and type in;

http://static.afbeeldinguploaden.nl/1303...0OS3s5.png

Now when you run it it will ask for your mothers age , dads age and then print those together out. Let's expalain these lines a little better.

import time Here we imported our time module.


first = input("What's your mother's age? "); Here we let the user assign a value to our variable "first".
second = input("What's your Father's age? ");Here we let the user assign a value to our variable "second".
time.sleep(3) Here we tell python to use the sleep function from the module time to pause the program.
print "Your mom and dad are together:" , first + second Here we tel python to print out a message, followed by our first and second variable using the "+" sign.


Chapter 9 -Raw input..

The difference between raw input and regular input is that python sees raw input as a string and with the regular input as an expression.

Now let's open our python shell and type in; ogkush = input("What's your name? ")

Hit enter..

http://static.afbeeldinguploaden.nl/1303/31913/dvhy.png

As you can see we get an error, as i said before you learn from these errors, now the reason why we get this error is because python does not see the regular input as a string and can therefor not print it, that's why it would only work with numbers which are not seen as strings.

http://static.afbeeldinguploaden.nl/1303...7DPNBm.png

But of course we also want to use strings so users can input them, this is why Python added Raw_input, it can pretty much be used the same like you can see below;

http://static.afbeeldinguploaden.nl/1303/31915/VqZ.png

So basically if you want the user to respond with a string, you use raw_input , if you want them to respond with a number, you use the regular input.
Never ignorant getting goals accomplished.

[Image: 1801a69d9f.gif]
Chapter 10 -Commenting out a line..

To comment out certain lines we can use the simple "#" character (no quotes)

Let's say we want to add a comment next to a code as a note, we can do this by typing;

Code
print "Hey there" #This print a message

Chapter 11 -New line

To start a new line in python we can use the following;

Let's say we want to print out information in only 1 line but want python to display certain parts on a line below..

We can do this by typing;
Code
print "Hey bob, \n How are you today? \n Sweet."

This will appear like;
Hey bob,
How are you today?
Sweet.

[img]http://static.afbeeldinguploaden.nl/1303/31916/d6I8.png[/img]

Chapter 12 -First piece of coding!

Go ahead and open a new python window it's time for another small code, we're going to try to use all the best chapters we had.

Now you can type the following; (see picture i don't want you to copy past)

[img]http://static.afbeeldinguploaden.nl/1303/31917/sMu5iY2F.png[/img]

This is the result;

[img]http://static.afbeeldinguploaden.nl/1303/31918/IRBL4nD.png[/img]

Try writing a code like this without looking back, if you cheat you just lie to yourself, simple.
Never ignorant getting goals accomplished.

[Image: 1801a69d9f.gif]
Reserved for guide Updates!

Will be adding new chapters daily!
Never ignorant getting goals accomplished.

[Image: 1801a69d9f.gif]
Very detailed guide. Keep the great threads coming.
(Mar 26, 2013 04:01 PM)Maple ‎‎ Wrote:  Very detailed guide. Keep the great threads coming.

Thank you mate, will definitely try to update this as much as possible.

Kind regards OG Kush.
Never ignorant getting goals accomplished.

[Image: 1801a69d9f.gif]
Amazing guide definitely a must read! Looks noob friendly!
[Image: hytaJjl.png]
(Mar 26, 2013 04:12 PM)Miki Wrote:  Amazing guide definitely a must read! Looks noob friendly!

Ye i tried my best keeping it as simple as possible but it's not quite easy explaining it the best way possible with English not being my birth language.

Kind regards, OG Kush.
Never ignorant getting goals accomplished.

[Image: 1801a69d9f.gif]
Quote:A functions is pretty much a sort of build in program in python.

No, no it is not...

Quote:line 2: We used the print function to print something on the screen.

You are using python 2.7.3 in which case, print is not a function. Print is a special statement. In Python 3.x however, they have made print a function.

Quote:Now let's open our python shell and type in; ogkush = input("What's your name? ")[

Never use input in this circumstance. It is a bad habit to get into. Use int(raw_input()) instead as input() passes through eval which can be very dangerous if a person knows what they are doing.

I looked over this for a minute and this is what I could pick out. This is why I am against people who don't know the language extremely well to make guides. All that ends up happening is people learning bad habits and incorrect things about the language. I would always suggest getting a book or even an eBook by a reputable author or someone who knows exactly what they are talking about over a guide like this.

But hey, what the fuck do I know? I've only being learning Python for just over 2 years so I am still a beginner. Up to you guys to listen to me or not, Idc either way.
If more of us valued food and cheer and song above hoarded gold, it would be a merrier world
~Thorin Oakenshield
(Mar 26, 2013 04:20 PM)-Legacy- Wrote:  No, no it is not...

You are using python 2.7.3 in which case, print is not a function. Print is a special statement. In Python 3.x however, they have made print a function.

Never use input in this circumstance. It is a bad habit to get into. Use int(raw_input()) instead as input() passes through eval which can be very dangerous if a person knows what they are doing.

I looked over this for a minute and this is what I could pick out. This is why I am against people who don't know the language extremely well to make guides. All that ends up happening is people learning bad habits and incorrect things about the language. I would always suggest getting a book or even an eBook by a reputable author or someone who knows exactly what they are talking about over a guide like this.

But hey, what the fuck do I know? I've only being learning Python for just over 2 years so I am still a beginner. Up to you guys to listen to me or not, Idc either way.

I'm definitely not a professional at all, i do understand the language pretty well and get what you mean, tho people can always choose whether they wish to follow a guide like this or a professional e-book.

I must say threads like this in general are more understandable as it is meant to guide people that are new to this language.
Other then the few "bad habits" i have apparently used i still find that there's allot of useful information in this guide.

Thank you for your opinion, OG Kush.
Never ignorant getting goals accomplished.

[Image: 1801a69d9f.gif]
There's a few nicks and nacks here and there, but in all you have a great guide. If users are truly active in this section, they'll know the differences.
Looks like a very detailed guide, I'll be bookmarking this to return :p
Thank you, i will be checking in a few if i made any mistakes here and there will be trying to add some more chapters by the end of the day.

Kind regards, OG Kush.
Never ignorant getting goals accomplished.

[Image: 1801a69d9f.gif]
Looks good, but I beg you, don't advocate the use of .sleep ;)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by AeroBlueJun 29, 2019 04:37 PM 7 482 Jun 29, 2019 04:37 PM
Last Post: TGilb94
[Java] by CupOfJavaOct 25, 2018 03:28 PM 12 809 Oct 25, 2018 03:28 PM
Last Post: Andsworth
[C#] by SkyCloudsSep 28, 2017 05:37 PM 6 389 Sep 28, 2017 05:37 PM
Last Post: Skylumz