Python The Worlds Most flexible and easist Language..

gayan kalhara

Member
Nov 22, 2007
7,060
48
0
I noticed that there are so many guys who try to be a programmer through low, incompleated, Complicated and Sucks Programming languages like VB,

So i thought to post my new book "python for Sri lankans." So i hope this would be very helpfull to you guys..

Lets start by a little Pamporiyak..

When I was in Grade 8 (three years ago) I realize the Fake that carring by Microsoft by Their Fuc*ing Promoting campains. until then i was also traped to them.

And i started to find a programm language to be a successfull programmer. After 2 months of Damn searching i found that the Best and most flexible language is PYTHON..

It's simple there are no DAmn"Vatarown" to do simple things..

Ex= if you have to add 2 to 1 we only have to type 1+2. But think in VB how much codes we have to wirte????

The desition is yours. If you learn and be a expert on Python. You got a bright future.. But if you follow VB ?????????


(After being a python guy, The Google invites me to work for them" Yes i'm on ly 14 at those days" they don't care my age and i was promoted as the cheif programmer for google Geo locater team.. (for South asia) and Now i'm the Commander of Hacking and Cyber developing Network..

Now what do you think???? All of these thing are given by Python.. SO what do you think??????
 

gayan kalhara

Member
Nov 22, 2007
7,060
48
0
If you can't wait until the end.. You can Get the Complete book. But thats not for free But for little amount to cover my Power Cost.. less than you think....

PM or mail me. [email protected]

If i'm wrong in following deatails please Comment here. or mail me.

If you have any Problem. Feel Free Of PM or mailing me. I'll try to solve as i can...
 
Last edited:

gayan kalhara

Member
Nov 22, 2007
7,060
48
0
Part 1 Intro

Intro
1.1 First things first
So, I think you’ve never programmed before. As we go through this tutorial I will attempt to teach you how to program.
There really is only one way to learn to program. You must read code and write code. I’m going to show you lots of
code. You should type in code that I show you to see what happens. Play around with it and make changes. The worst
that can happen is that it won’t work. When I type in code it will be formatted like this:

##Python is easy to learn
print "Hello, World!"

That’s so it is easy to distinguish from the other text. To make it confusing I will also print what the computer outputs
in that same font.
Now, on to more important things. In order to program in Python you need the Python software. If you don’t
already have the Python software go to http://www.python.org/download/ and get the proper version for your platform.
Download it, read the instructions and get it installed.
1.2 Installing Python
First you need to download the appropriate file for your computer from http://www.python.org/download. Go to the 2.5
link (or newer) and then get the windows installer if you use Windows or the rpm or source if you use Unix.
The Windows installer will download to file. The file can then be run by double clicking on the icon that is downloaded.
The installation will then proceed.
If you get the Unix source make sure you compile in the tk extension if you want to use IDLE.
1.3 Interactive Mode
Go into IDLE (also called the Python GUI). You should see a window that has some text like this:
1
Python 2.5 (#4, Dec 12 2007, 19:19:57)
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>>
The >>> is Python way of telling you that you are in interactive mode. In interactive mode what you type is immediately
run. Try typing 1+1 in. Python will respond with 2. Interactive mode allows you to test out and see what Python
will do. If you ever feel you need to play with new Python statements go into interactive mode and try them out.
1.4 Creating and Running Programs
Go into IDLE if you are not already. Go to File then New Window. In this window type the following:
print "Hello, World!"
First save the program. Go to File then Save. Save it as ‘hello.py’. (If you want you can save it to some other
directory than the default.) Now that it is saved it can be run.
Next run the program by going to Edit then Run script. This will output Hello, World! on the
*Python Shell* window.
Confused still? Try this tutorial for IDLE at http://hkn.eecs.berkeley.edu/ dyoo/python/idle intro/index.html
1.5 Using Python from the command line
If you don’t want to use Python from the command line, you don’t have too, just use IDLE. To get into interactive
mode just type python with out any arguments. To run a program create it with a text editor (Emacs has a good
python mode) and then run it with python program name.
 
Last edited:

gayan kalhara

Member
Nov 22, 2007
7,060
48
0
Hello, World

2.1 What you should know

You should know how to edit programs in a text editor or IDLE, save them to disk (floppy or hard) and run them once
they have been saved.
2.2 Printing

Programming tutorials since the beginning of time have started with a little program called Hello,World! So here it is:

print "Hello, World!"

If you are using the command line to run programs then type it in with a text editor, save it as ‘hello.py’ and run it with
“python hello.py”
Otherwise go into IDLE, create a new window, and create the program as in section 1.4.
When this program is run here’s what it prints:

Hello, World!

Now I’m not going to tell you this every time, but when I show you a program I recommend that you type it in and run
it. I learn better when I type it in and you probably do too.

Now here is a more complicated program:

print "Jack and Jill went up a hill"
print "to fetch a pail of water;"
print "Jack fell down, and broke his crown,"
print "and Jill came tumbling after."

When you run this program it prints out:
Jack and Jill went up a hill
to fetch a pail of water;
Jack fell down, and broke his crown,
and Jill came tumbling after.


When the computer runs this program it first sees the line:
print "Jack and Jill went up a hill"
so the computer prints:
Jack and Jill went up a hill
Then the computer goes down to the next line and sees:
print "to fetch a pail of water;"
So the computer prints to the screen:
to fetch a pail of water;
The computer keeps looking at each line, follows the command and then goes on to the next line. The computer keeps
running commands until it reaches the end of the program.

2.3 Expressions


Here is another program:
print "2 + 2 is", 2+2
print "3 * 4 is", 3 * 4
print 100 - 1, " = 100 - 1"
print "(33 + 2) / 5 + 11.5 = ",(33 + 2) / 5 + 11.5
And here is the output when the program is run:
2 + 2 is 4
3 * 4 is 12
99 = 100 - 1
(33 + 2) / 5 + 11.5 = 18.5

As you can see Python can turn your 50 thousand RS computer into a 150 RS calculator.

Python has six basic operations:
Operation Symbol Example
Exponentiation ** 5 ** 2 == 25
Multiplication * 2 * 3 == 6
Division / 14 / 3 == 4
Remainder % 14 % 3 == 2
Addition + 1 + 2 == 3
Subtraction - 4 - 3 == 1
Notice that division follows the rule, if there are no decimals to start with, there will be no decimals to end with. (Note:
This will be changing in Python 2.3) The following program shows this:

4 Chapter 2. Hello, World

print "14 / 3 = ",14 / 3
print "14 % 3 = ",14 % 3
print
print "14.0 / 3.0 =",14.0 / 3.0
print "14.0 % 3.0 =",14 % 3.0
print
print "14.0 / 3 =",14.0 / 3
print "14.0 % 3 =",14.0 % 3
print
print "14 / 3.0 =",14 / 3.0
print "14 % 3.0 =",14 % 3.0
print
With the output:
14 / 3 = 4
14 % 3 = 2
14.0 / 3.0 = 4.66666666667
14.0 % 3.0 = 2.0
14.0 / 3 = 4.66666666667
14.0 % 3 = 2.0
14 / 3.0 = 4.66666666667
14 % 3.0 = 2.0

Notice how Python gives different answers for some problems depending on whether or not there decimal values are
used.

The order of operations is the same as in math:
1. parentheses ()
2. exponents **
3. multiplication *, division \, and remainder %
4. addition + and subtraction -

2.4 Talking to humans (and other intelligent beings)

Often in programming you are doing something complicated and may not in the future remember what you did.
When this happens the program should probably be commented. A comment is a note to you and other programmers
explaining what is happening. For example:
#Not quite PI, but an incredible simulation
print 22.0/7.0
Notice that the comment starts with a #. Comments are used to communicate with others who read the program and
your future self to make clear what is complicated.
 
Last edited:

sri_lion

Member
Sep 14, 2006
12,908
102
0
Kuala Lumpur
nagaya said:
ela macho....keep up gd wrk.....
f**k the M$ shit,,,,,,

I know how you feel bro.. but you cannot have that attitude when you are out there with the real clients building enterprise grade applications.. its good to know everything! :)
 

madurax86

Member
Jun 29, 2006
4,385
88
0
ey Bro load up a OpenGL window on python and send it to me[compiled exe] coz VB does it very easily if you want to tell other people what language to use tell them about g++, mingw32 compiler MS is a company and Google is a company too u knw there;s nothing called MS not gud and Google gud its just that MS progs[the new ones mostly] suck; googles programs dont suck but all they want in return is money you'd get to know of this if you had used or read the articles about AdSense here. VB6 was released on 97 still its being used for building enterprise applications i downloaded python on around 2006 but i didnt like the whole interpreter thing seemed like slow...[for me, did no bencheis]
If you want to know for yourself a programming language[not for making money or to support big companies] use c++ or c you can make money after learning it fully MS doesnt provide enough support for c++ thats because its the key language to be a great programmer :P
 

gayan kalhara

Member
Nov 22, 2007
7,060
48
0
mizt said:
alot of mobile symbian application use python too

Not only than NASA is using Python for their needs (DO you know.. Colombia's Programs was prepared by using Microsoft Programing language "uniqe", But Where is Colombia Today?????:lol:)
 

gayan kalhara

Member
Nov 22, 2007
7,060
48
0
Part 5 Who Goes There?

3.1 Input and Variables

Now I feel it is time for a really complicated program. Here it is:

print "Halt!"
s = raw_input("Who Goes there? ")
print "You may pass,", s

When I ran it here is what my screen showed:

Halt!
Who Goes there? Josh
You may pass, Josh

Of course when you run the program your screen will look different because of the raw_input statement. When you ran the program you probably noticed (you did run the program, right?) how you had to type in your name and then press Enter. Then the program printed out some more text and also your name. This is an example of input. The program reaches a certain point and then waits for the user to input some data that the program can use later. Of course, getting information from the user would be useless if we didn’t have anywhere to put that information and
this is where variables come in. In the previous program s is a variable. Variables are like a box that can store somepiece of data. Here is a program to show examples of variables:

a = 123.4
b23 = ’Spam’
first_name = "Bill"
b = 432
c = a + b
print "a + b is", c
print "first_name is", first_name
print "Sorted Parts, After Midnight or",b23
And here is the output:
a + b is 555.4
first_name is Bill
Sorted Parts, After Midnight or Spam


Variables store data. The variables in the above program are a, b23, first_name, b, and c. The two basic types
are strings and numbers. Strings are a sequence of letters, numbers and other characters. In this example b23 and
first_name are variables that are storing strings. Spam, Bill, a + b is, and first_name is are the strings
in this program. The characters are surrounded by " or ’. The other type of variables are numbers.
Okay, so we have these boxes called variables and also data that can go into the variable. The computer will see a line
like first_name = "Bill" and it reads it as Put the string Bill into the box (or variable) first_name. Later
on it sees the statement c = a + b and it reads it as Put a + b or 123.4 + 432 or 555.4 into c.

Here is another example of variable usage:

a = 1
print a
a = a + 1
print a
a = a * 2
print a
And of course here is the output:

1
2
4

Even if it is the same variable on both sides the computer still reads it as: First find out the data to store and than find out where the data goes.

One more program before I end this chapter:

num = input("Type in a Number: ")
str = raw_input("Type in a String: ")
print "num =", num
print "num is a ",type(num)
print "num * 2 =",num*2
print "str =", str
print "str is a ",type(str)
print "str * 2 =",str*2
The output I got was:
Type in a Number: 12.34
Type in a String: Hello
num = 12.34
num is a <type ’float’>
num * 2 = 24.68
str = Hello
str is a <type ’string’>
str * 2 = HelloHello

Notice that num was gotten with input while str was gotten with raw_input. raw_input returns a string while input returns a number. When you want the user to type in a number use input but if you want the user to type in a string use raw_input. The second half of the program uses type which tells what a variable is. Numbers are of type int or float (which 10 Chapter 3. Who Goes There?
are short for ’integer’ and ’floating point’ respectively). Strings are of type string. Integers and floats can be worked on by mathematical functions, strings cannot. Notice how when python multiples a number by a integer the expected thing happens. However when a string is multiplied by a integer the string has that many copies of it added i.e. str * 2 = HelloHello.
 

gayan kalhara

Member
Nov 22, 2007
7,060
48
0
All Of these Parts Have Exercises to improve the Skills. But If i post them here This Gonna real Mess.. So If you want to get them request here. I'll start a New thread..
 

x-pert

Member
Jun 13, 2006
20,952
77
0
Are you the author of this book?
Good job if you're the author.


But Python is not good for the industry. It uses an interpreter rather than a compiler at the first place. For penetration testing, python is good. But that's a small area of the IT world.

World is moving towards Java and .NET apps. And still people use C language a lot. So the best starting point to learn programming is C language in my opinion. Many languages are built on top of C.
 

nagaya

Member
Mar 18, 2007
12,671
194
0
Yeah i think C/C++ is best;BTW do u have any native compiler fof python....rather than using the intepreter?
 

nagaya

Member
Mar 18, 2007
12,671
194
0
sri_lion said:
I know how you feel bro.. but you cannot have that attitude when you are out there with the real clients building enterprise grade applications.. its good to know everything! :)
u mean shld we go for .net fw?:confused: