Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Learning Python part 1 (Getting started and first program)

hello world variable type

  • Please log in to reply
5 replies to this topic

#1 saeras

saeras

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 64 posts

Posted 11 February 2010 - 05:07 AM

part 1 Getting started and first program

Installing python:
To get started on using python you have to install an interpreter(I believe this is the correct word for it). This can be found at Python Programming Language -- Official Website while there are many different versions i recomend starting with version 2.6.4, there's a newer version 3.1.1 but this isn't completley backwards compatible to the 2.x.x versions. And seeing how most programs are coded in the 2.6.4 version it would be a better start. Don't worry though the differences arent major and adapting to 3.x will be a minor task.

When you have installed python i would also recommend getting News pygame - python game development as i will use this later on. This is a great an easy module for making games. But you can save this for later if you want to.

Compiling?:
Python is an interpretive language. Basically this means that your code won't have to be compiled before you run it. This makes it easy to test run it and squash those nasty bugs. If you wanna know exactly what being an interpretive language means you can read about it here Interpreted language - Wikipedia, the free encyclopedia .

Choosing and IDE:
Now you have python fully installed and ready to go. But you'll need an IDE to write your programs in, while the notepad does work it's not very efficient and lacks features. luckily python provides an excelent IDE called IDLE. IDLE provides a pretty powerfull editor and a command line. The command line is basically running your program while typing it. What this allows you to do is try things out in an easy manner. For exapmle, say you want to try how an str will behave when its run in a special function and you dont want to go through the hassle of saving a module and all that. While IDLE is great I would recommend this VIM as Python IDE | Alain M. Lafon . That's what I'm using atm and I think it's great, if this doesn't fit your taste though there are lots of other great IDE's, I won't name any here but a quick google search should give you lots of IDE's to choose from.

Writing your first application:
This is as easy as opening the command line and write

print('Hello World') 

But we'll want to save the programs we make too. What you have to do is open the IDE of your choice and write these lines.

print('hello world') #prints out hello world.
raw_input('press enter key to exit') #this is to keep the program running.

Then you save this as hello world.py and running this file should open a cmd window saying
hello world
press any key to exit

This concludes part 1 stay tuned for part 2 where i will go over syntax and variable types.

Feel anything have been left out? Had trouble with something? Or want something changed?
Post a comment about it and I will see what I can do.
  • 2
Posted Image

#2 James.H

James.H

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 569 posts

Posted 11 February 2010 - 09:35 AM

Hey it worked like a treat! Cool :)

Am looking forward to the next part!

Good work saeras, very easy to follow.
  • 0

#3 saeras

saeras

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 64 posts

Posted 11 February 2010 - 11:30 AM

I'm glad you liked it. Part 2 should be right around the corner. ^^
  • 0
Posted Image

#4 exicute

exicute

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 146 posts

Posted 11 February 2010 - 03:01 PM

Worked and understood. Great tut, I wasn't aware that python was an interpretive language. ;D +rep
  • 0
Posted Image
My Tutorials|Build A Computer|Cat 5E|

#5 Prog4rammer

Prog4rammer

    CC Newcomer

  • Just Joined
  • PipPip
  • 14 posts

Posted 09 March 2010 - 05:17 AM

its useful and very Cool Begin !..
Very Good I Waiting the all Parts Tutorial :)
  • 0

#6 Guest_Alexander_*

Guest_Alexander_*
  • Guest

Posted 25 March 2010 - 12:41 AM

Wow, thanks, straightforward tut, nice:D
If you're working in python 3, you should replace raw_input with input, to get rid of the name error.
should look something like this:
input('press enter key to exit')
  • 0





Also tagged with one or more of these keywords: hello world, variable type

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download