Hello There, Guest!  
Poll: IS THIS HELPFUL TO YOU?
This poll is closed.
YES. Its helpful.
89.47%
17
89.47%
NO.
5.26%
1
5.26%
I DON'T KNOW WHAT IT IS.
5.26%
1
5.26%
* You voted for this item.
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5

★ P Y T H O N ★ - MEGA TUTORIAL THREAD

#1
[Image: 2yw9zi9.jpg]

GPRSHUB PRESENTS A MEGA TUTORIAL & GUIDE ON PYTHON. THIS IS A LEARNING AND DISCUSSION THREAD FOR PYTHON PROGRAMMING.

Python is a great object-oriented, interpreted, and interactive programming language. It is often compared to Lisp, Tcl, Perl, Ruby, C#, Visual Basic, Visual Fox Pro, Scheme or Java... and it's much more fun. Python is one of the most powerful adaptable general purpose languages.


[Image: python-logo.png]

Introduction to PYTHON


Python is an interpreted, high-level, programming language. Used in many applications and for many purposes. It was designed to be easy to read and does this by using something that most programming languages don't use, whitespace. Whitespace is the indention of lines code, through tabbing (or manually adding spaces). It supports multiple programming styles, and can be implemented as scripts or through other methods.

Why PYTHON?


Python has many uses and is easy for beginning programmers to learn. It can be useful if you continue to use it, but also if you're only learning it to understand the mechanics of programming and/or scripting.

Quote:One advantage I think is with Python, you can debug at the source level, increasing productivity. You can write and test your programs instantly, and find any possible errors in seconds!


Python combines remarkable power with very clear syntax. It has modules, classes, exceptions, very high level dynamic data types, and dynamic typing. There are interfaces to many system calls and libraries, as well as to various windowing systems. New built-in modules are easily written in C or C++ (or other languages, depending on the chosen implementation). Python is also usable as an extension language for applications written in other languages that need easy-to-use scripting or automation interfaces.

Where is it used?


Python can be ran on almost any OS. While it is not native to Windows machines, it is native to most Linux distributions. The great thing with Python is its flexibility and usefulness in many environments.

What can be done with PYTHON?

Python is not limited to your local machine. You can write Python programs/scripts to interact with other computers, either on your Local Area Network (LAN) or across the Internet. Python can be used to make interactive webpages and some of the best programs.

Some of the popular programs are made in Python. A few examples include:

•BitTorrent
•Blender 3D
•Battlefield 2
And many more! You can find a huge list of programs made in Python
Hidden Content This content is hidden from you. If you want to see it you have to register on this board.

As you can see, many popular programs are created using Python. Keep Reading this tutorial on GprsHub and you can make these programs too!

[Image: icXvHC.png]

Which PYTHON Version to choose?


Many people will have many different opinions on which Python version to choose. Personally, I use either Python 2.6 or 2.7. The reason I use 2.6 is because it is supported, meaning that it has the most support and additional modules as of this time. In the future, Python may offer support for versions 3.x.

I also use Python 2.7 because it is what some people call future-proof. This means that 2.7 was written after 3.x, so it offers some compatibility between the two.

Currently, Python 2.x would be your best bet. Name companies, such as Google, still use the 2.x versions of Python. So can you. Do NOT feel pressured to need the latest versions, they are not always the best.
In this case, functions are handled differently and some things have a different syntax. It can get confusing for a new user.


Download and Setup PYTHON


To download Python, you need to Go here:
Hidden Content This content is hidden from you. If you want to see it you have to register on this board.

Once you have downloaded the appropriate file (if you are not sure, use the first download link) run the MSI file and leave all options at default. It should install at "C:\Python27" with the numbers as your Python version. If it did not install that, no worries, anywhere is fine.
(Note** Many Linux Distributions already include Python.)


Now How does Python Works


Please note I am using Python from Windows but in future I will also upload some material for Linux also.
To make sure Python is working, press the Windows Start Button (bottom left) and type in "python" (assuming you have Windows Vista/7, if not, use 'Run' to run "python") and press enter. You should see a DOS type of box appear on the screen with the insertion mark ("_") after three arrows '>>>'.

If you can see this, Python is installed correctly! Good job, now let's move on to coding!


The Python Syntax


Python's syntax is extremely easy to learn. Unlike many programming languages, it does NOT require a semi-colon (";") at the end of every line. That is a change for most people.

Another thing is that Python uses 'white-space' instead of curly brackets ("{}") to separate functions and classes. This keeps the source neat and very easy to understand. Due to the simple syntax and readability of code, it is easy to pick up another coders work from nearly any point in their project. This gives Python loads of flexibilty with collaborative projects.

Another good thing to remember with Python is that it IS case sensitive. This means that "apple" is different that "Apple". This is important.

I also want to point out now, you can add a comment to a Python program using the pound ('#') symbol. Use it like so:

Code:
#This is a comment!


Comments are ignored by the interpreter and usually are only used to include version information or to keep notes on the source code.

Hello World!


It is time for what many of you have been waiting for. Programming. Scripting. Whatever you would like to call it. It is starting now, so get ready!

Okay, so as with many programming languages, I will start out with a simple program, which is called 'Hello World'. What this program will do is display the text "Hello World!" on the screen and await user input to close.

Alright, so you will need to open up IDLE (for Windows users). This can be done by typing 'IDLE' in the Windows Vista/7 search box in the Start Menu. Once that opens, go to 'File' and click 'New Window'. This gives us a blank page for us to write out our programs.

Alright! All set up, time for some code!

Here is the first bit of code we will use:

Code:
print "Hello World!"


Do NOT copy that straight into IDLE. Instead, type it out yourself, you will benefit more in the end.
What this code does is tell Python to Display (print to screen) the following to the screen. Since we enclosed the text ("Hello World!") in quotes, that means it is a string. A string just means text, no numbers. Simple.

So that one lines of code displays "Hello World!" to the screen. The only problem is that if you try running this, it will close instantly, so let us add some code to stop it.


Code:
print "Hello World!"
raw_input("Press <enter> to close.")

Type that out into your text editor.

"raw_input()" is a simple way to grab data from the user. It is called input. You may have noticed the quotes in the "raw_input()". Let me explain. That function by itself without the quotes ["raw_input()"] would work 100% to keep your program from instantly shutting down, but the quotes with text gives the user instruction of what to do. This is important.

So now that you have those two lines of code, either go to 'File' > 'Save' ('Save As') or press 'CTRL' + 'S'. This comes up with the save window. Due to simplicity, you can save the file at your desktop. By default, it should have the option to either save as a "*.txt" file or a "*.py" file. In our case, we want a "*.py" file.

So type in the file name bar: "example.py"
Then hit 'Save'.


From here, you have a few different options. You can double-click or run the file as you would any program. Doing this will result in the following on your screen:

[Image: 25zru3p.jpg]

When you press enter, the program will end.

Another way you can run the program is to just press 'F5' after you save it (while the IDLE text editor is open). This will open it in Python's native debugger. This is very useful when writing large projects, as it can pinpoint exact errors in your coding.



In Linux, simply type the following into the terminal to run the file:
Code:
python fileName.py


-----------------------
Math Functions and Variables


Hello All GprsHub Members today I will explain how to use Mathematical operators in Python. In any programming language, Mathematics and Variables are of KEY importance. You cannot possibly write a leading program without them. They are they key to programming, so without further ado, lets explain how they work in Python.

Firstly, a variable can hold assorted types of data.

These include:


• Integers (int)
• Strings (str)
• Boolean Values (True or False)


We will cover those three in this section.

In Python, it is beyond easy to declare a variable. All you have to do is type the variable name and its value. A variable can be named nearly anything (do not use spaces though!) so it is very flexible. In my examples, I will use an assortment of words and single letters as variables.


This is how you declare a string variable:

Code:
x = "This is a string"


What happened? First, you have the variable name (in this case 'x'). Then, you put an '=' sign. Finally, you put its value, enclosed in quotes. With python, you can use single quotes or double quotes, the choice is up to you.

Now let us use the integer variable type.


Code:
y = 23


Could that get any easier? Again, all you have to do is type the variable name, an equal sign, and its value. With integers, you do not use quotes. If you do use quotes with a number, it will be treated as a string and NOT a number. So with integers, leave out the quotes.

Finally, we have the Boolean variable type. This holds only two different options. True or False. You declare Boolean variables like this:


Code:
z = True
a = False


Simple. You either write 'True' or 'False' (remember, case matters!).

Now that Variables are covered, it is time for basic math functions.

The first one I will cover it addition and subtraction.
If you can program, you should already know how this works, mathematically, but let me show you how it works in Python.

You can use IDLE for this. Use this snippet of code:


Code:
print 4+5
print 7-3


If you run that program, you will get the following output:

Code:
9
4


Basic math. With addition and subtraction, you can only use integer values.

Now, multiplication and division.

Multiplication ("*") can be handled with String variables and Integer variables. For example, use the following snippet of code:


Code:
x = 5
y = "5"
print x * 5
print y * 5


Your output will be:

Code:
25
55



For the integer variable, it is self-explanatory, basic math. However, the string variable acted differently! When you multiply a string variable, it just repeats itself. Simple enough, right?

Now time for division (and modulus).

To divide with Python, use the division sign ("/")

Code:
x = 20
print x / 4


Your output will be '5'.
With Python, if you try dividing numbers that will result in a decimal value, you have to include a decimal place in the operation. Let me show you in action.

Code:
print 20 / 3
print 20 / 3.0


If you run that, you will get the following output:
Code:
6
6.667


The simple ".0" makes a big difference. Always remember to include a decimal place somewhere when using division!

Earlier, I mentioned modulus ('%') with division, because they are very similar. When you were younger, you were probably taught how to divide and then how to 'leave the remainder'. This is exactly what modulus does. It does the division and gives you the remainder. Lets see how it works.


Code:
print 20 % 5
print 20 % 3


Your output will be:
Code:
0
2


Simple. All modulus does if give you the remainder.

The last math function I will show you is exponents ('**'). An exponent tells you how many times to multiply a number. For example, '6**3' is the same as '6*6*6'. Let us see Python work this out.


Code:
print 8**4


Your output will be:

Code:
4096


Simple. You should have already been familiar with all of these math operations, but now you know how to utilize it in Python!

One more thing with variables..

They can either be local, or global. This will be important later in the tutorial, when function definitions are included, but this is how you make a variable global (used everywhere in the program).

Code:
global x

Note: 'x' here is the variable.




TO SEE THIS THREAD UPDATED VOTE ON THE POLL ABOVE AND COMMENT

I YOU LIKE THE TUTORIAL HIT +REP OR THANKS BUTTON.

DO NOT REPRODUCE THIS WITHOUT PERMISSION. IF YOU WANT TO USE THIS MATERIAL PM ME OR COMMENT.


.......MORE TUTORIAL AND GUIDE/INTRO WILL BE UPDATED SOON. DO SUBSCRIBE TO THIS THREAD TO BE UPDATED. KEEP VISITING GPRSHUB
KEEP VISITING GPRSHUB.COM FOR LATEST
TRICKS | EXPLOITS | UPDATES

FOR ANY QUERY PM ME
 Reply
#2
THREAD UPDATED MARCH 12!!
KEEP VISITING GPRSHUB.COM FOR LATEST
TRICKS | EXPLOITS | UPDATES

FOR ANY QUERY PM ME
 Reply
#3
thanks bro

interesting language

i m your student...keep update daily
 Reply
#4
I WILL UPDATE IT DAILY. BUT IT MUST GET PROPER VIEWS OR INTEREST.
KEEP VISITING GPRSHUB.COM FOR LATEST
TRICKS | EXPLOITS | UPDATES

FOR ANY QUERY PM ME
 Reply
#5
TUTORIAL UPDATED - MARCH 14

KEEP VISITING GPRSHUB
KEEP VISITING GPRSHUB.COM FOR LATEST
TRICKS | EXPLOITS | UPDATES

FOR ANY QUERY PM ME
 Reply
#6
Bro add more about it
 Reply
#7
really NYC nd easy to learn ..update it daily
 Reply
#8
Like your work..... keep it.....
[Image: v64txz.jpg]
 Reply
#9
keep it nice work
 Reply
 
 
Forum Jump:

Users browsing this thread: 1 Guest(s)