Jump to content

Learning Python part 1 (Getting started and first program)

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
saeras

saeras

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
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.
Posted Image

#2
James.H

James.H

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 866 posts
Hey it worked like a treat! Cool :)

Am looking forward to the next part!

Good work saeras, very easy to follow.

#3
saeras

saeras

    Learning Programmer

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

#4
exicute

exicute

    Programming Expert

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

#5
Prog4rammer

Prog4rammer

    Newbie

  • Members
  • PipPip
  • 14 posts
its useful and very Cool Begin !..
Very Good I Waiting the all Parts Tutorial :)
[SIGPIC][/SIGPIC]
Some Words Me : "♪●Software Engineer and Love Programming in Java and PHP under Ubuntu System ... ♪♥ " :)

#6
Guest_Alexander_*

Guest_Alexander_*
  • Guests
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')