Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Python (http://www.go4expert.com/articles/python-tutorials/)
-   -   Introduction to Python (http://www.go4expert.com/articles/introduction-to-python-t1034/)

pradeep 20Jul2006 19:00

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 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.

ash_work 9Jul2007 18:25

Re: Introduction to Python
 
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.

eluminoustech 30Jun2009 14:49

Re: Introduction to Python
 
Thanks for the Information..... it is really helpful...

mani333 5Aug2010 11:26

Re: Introduction to Python
 
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

johngate2100 16Aug2010 22:09

Re: Introduction to Python
 
When i was young boy ,I started programing from C++.

szoasis 23Nov2010 08:31

Re: Introduction to Python
 
Thanks for the Information!
It is really helpful!

wowogolf 28Jun2011 12:30

Re: Introduction to Python
 
Quote:

Originally Posted by szoasis (Post 75116)
thanks for the information!
It is really helpful!

:d:d

Klusner 24Jan2012 16:53

Re: Introduction to Python
 
This is Klusner and i am new here.I need the cooperation of each and ever person here for the useful exchange of information.

jhonden 25Jan2012 11:48

Re: Introduction to Python
 
Is google is also made in Python. I heard one eveloper saying this.


All times are GMT +5.5. The time now is 07:15.