Introduction to Python

pradeep's Avatar author of Introduction to Python
This is an article on Introduction to Python in Python.
A few years ago, people who wished to study programming as a hobby had an important decision to make: Which programming language would they study for their first?

Many people chose to start with BASIC or Pascal, because they were easier. Indeed, those languages are fairly well-suited to hobbyist programming, for people with simpler needs, who basically just want a programming language that won't overwhelm them. But many professional programmers denounce BASIC and Pascal as bad for learning with, because they teach programmers "bad habits" which will be hard to break later on.

Some people just started with a professional-level language like C or Fortran. In fact, there really is nothing wrong with learning C as your first language, it's just harder to get into it. Still other people opted for "instructional" languages which are specifically categorized for people studying programming concepts, like Scheme or ALGOL. Although these languages might make nice learning tools, they have one problem: They're considered useless for real-world programming.

And so the budding programmers were left with a dilemma: Wasn't there a resonably easy-to-learn programming language which wouldn't enforce bad programming technique and which was useful for general-purpose programming? Classically, the answer was no.

But the computer industry moves on, as all industries will, and we've come a long way from the days when most hobbyists were cranking out BASIC code on Commodore 64s or Apple ][ systems. There's a new programming language which aims to be easy-to-learn, elegant, powerful, and useful. It's called Python.

Python is interpreted, not compiled (much like Perl). The Python interpreter is free and can be downloaded from www.python.org.

So now that you know what Python is, where's the tutorial? Right here:

OK, the first thing you might want to know about Python is, how do you print to the screen with it? Well, Python uses good old standard print. So Python's "Hello, World" program looks just like BASIC's:

Code: Python
print "Hello, World."
Printing variables is similarly easy. Guess what the following program does:

Code: Python
a = 2
  print 'a'
(Note the use of grave accents around the variable name.) If you're using the Python shell, in which commands are entered manually, one at a time, like at a command prompt, you can even forgo the "print" and just type the variable name alone, or the output that you want to display. This may lead you to believe that Python automatically outputs the result of an operation without you needing to use the "print" command. However, this is true only when using the Python shell, not when using program scripts. The shell will behave this way, but actual saved Python program won't. Previously, this page incorrectly stated that a "command" containing the variable name alone would work correctly. I apologize for any inconvenience my misinformation may have caused; I guess that's what I get for having my only actual Python experience be with the shell. My sincere thanks also go to Grail for pointing this mistake out to me and saving me from further embarrassment. =)

Here's a program showing you how to make a socket in Python:

Code: Python
from socket import *
  HOST = 'www.whatever.com'    # The remote host
  PORT = 80                    # The same port as used by the server
  s = socket(AF_INET, SOCK_STREAM)
  s.connect(HOST, PORT)
  s.send('GET / HTTP/1.0')
  data = s.recv(1024)
  s.close()
  print 'Received', `data`
There you have it.Keep experimenting with Python as you do with other languages.
0
ash_work's Avatar
Newbie Member
I recently wrote an article about Python and I think it has a lot of scope when teamed with XML. If you would like to have more info on python, visit the Oracle official site which has info for XML and Python.
0
eluminoustech's Avatar, Join Date: Jun 2009
Newbie Member
Thanks for the Information..... it is really helpful...
0
mani333's Avatar, Join Date: Aug 2010
Newbie Member
hi,

pradeep
Introduction to Python
A few years ago, people who wished to study programming as a hobby had an important decision to make: Which programming language would they study for their first?

Many people chose to start with BASIC or Pascal, because they were easier. Indeed, those languages are fairly well-suited to hobbyist programming, for people with simpler needs, who basically just want a pr
0
johngate2100's Avatar, Join Date: Aug 2010
Light Poster
When i was young boy ,I started programing from C++.
0
szoasis's Avatar, Join Date: Nov 2010
Light Poster
Thanks for the Information!
It is really helpful!
0
wowogolf's Avatar, Join Date: Jun 2011
Newbie Member
Quote:
Originally Posted by szoasis View Post
thanks for the information!
It is really helpful!
:d:d
0
Klusner's Avatar
Newbie Member
This is Klusner and i am new here.I need the cooperation of each and ever person here for the useful exchange of information.
0
jhonden's Avatar, Join Date: Sep 2011
Ambitious contributor
Is google is also made in Python. I heard one eveloper saying this.