New to Python check this

13 Oct

First download python from here

After installing open python in command line.

Try this one liners

>>> print "Hello, World!"
>>> 1 + 1
>>> 18294+449566
(These are additions)
>>> 6-5
>>> 5**2
(Exponentials e.g. this one is 5 squared)

>>> print "1 + 2 is an addition"
1 + 2 is an addition
(the print statement, which writes something onscreen)


v = 1
print "The value of v is now", v
v = v + 1
print "v now equals itself plus one, making it worth", v
v = 51
word1 = "Good"
word2 = "Morning"
word3 = "to you too!"
print word1, word2


a = 0
while a < 10:
    a = a + 1
    print a
if a > 5:
    print "This shouldn't happen."
    print "This should happen."



One other point is that the code to be executed if the conditions are met, MUST BE INDENTED. That means that if you want to loop thenext five lines with a ‘while’ loop, you must put a set number of spaces at the beginning of each of the next five lines.



Define your own function like this

def hello():
    print "hello"
    return 1234


One Response to “New to Python check this”

  1. brittoc 10/15/2010 at 9:30 am #

    more detail

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: