Introduction to Python

Discussion in 'Python' started by pradeep, Jul 20, 2006.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    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:
    print "Hello, World."
    Printing variables is similarly easy. Guess what the following program does:

    Code:
      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:
      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.
     
  2. ash_work

    ash_work New Member

    Joined:
    Jul 9, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  3. eluminoustech

    eluminoustech New Member

    Joined:
    Jun 25, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for the Information..... it is really helpful...
     
  4. mani333

    mani333 New Member

    Joined:
    Aug 5, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  5. johngate2100

    johngate2100 New Member

    Joined:
    Aug 11, 2010
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.printingblue.com/
    When i was young boy ,I started programing from C++.
     
  6. szoasis

    szoasis New Member

    Joined:
    Nov 23, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.szoasis.com
    Thanks for the Information!
    It is really helpful!
     
  7. wowogolf

    wowogolf New Member

    Joined:
    Jun 28, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.24globalgolf.com/
    :d:d
     
  8. Klusner

    Klusner New Member

    Joined:
    Jan 24, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    This is Klusner and i am new here.I need the cooperation of each and ever person here for the useful exchange of information.
     
  9. jhonden

    jhonden New Member

    Joined:
    Sep 13, 2011
    Messages:
    190
    Likes Received:
    4
    Trophy Points:
    0
    Is google is also made in Python. I heard one eveloper saying this.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice