Python 2.7 Tutorial

Python How ToI asked you guys what video I should do next, and based on your votes you wanted a Python 2.7 Tutorial! Because of the tremendous interest, I will be rolling out a Massive tutorial for Python. I actually did one on Python 3.0 if you want that instead though. Here it is Python How to Video Part 1.

The tools I use in this tutorial include the Eclipse IDE and Pydev. I document how to install them in the video below, but also in this article Free IDE.

Now on with the video. All of this code will work with Python 2.5 thru 2.7. The code will follow the video. If you have any questions or comments leave them below. Here is all the code from the entire tutorial in a zip archive.

If you find this article helpful, please click here

so more people can find this :)

#! /usr/bin/python

# You don’t define variables in Python. They are chosen based on the value assigned

from math import sqrt

integerEx = 8
longIntEx = 22000000000000000000000
floatEx = 2.2
stringEx = “Hello”
booleanEx = True

print type(integerEx)
print type(longIntEx)
print type(floatEx)
print type(stringEx)
print type(booleanEx)

# Boolean Examples

booleanTwo = False

print booleanEx and booleanTwo
print booleanEx or booleanTwo
print not booleanTwo

# Number Examples

intOne = 7
intTwo = 99
floatOne = 7.9
floatTwo = 9.8

print intTwo / intOne # This should be 14.14
print float(intTwo) / float(intOne)
print int(floatOne)
print int(booleanTwo)

print intOne > intTwo
print intOne >= intTwo
print intOne < intTwo
print intOne <= intTwo
print intOne != intTwo
print intOne == intTwo

print intOne + intTwo
print intOne – intTwo
print intOne * intTwo
print intTwo % intOne
print intOne ** intTwo

print id(floatOne)

# Math Modules

print sqrt(intOne)

# Input from users

answer = raw_input(“What is your name? “)
print “Hello ” + answer

# String Basics

strOne = “Hello”
strTwo = “World”

print strOne, strTwo
print strOne + strTwo

longStr = ”’This is a very long string that \
goes on forever and ever”’

print longStr

print longStr[0:3]

# \\     Backslash (\)
# \’     Single quote (‘)
# \”     Double quote (“)
# \n     ASCII Linefeed

16 Responses to “Python 2.7 Tutorial”

  1. Jason says:

    I am slowly figuring things out. I’m not for sure what Eclipse to download from the vast list given on their web-page. I am trying to use regex within Python if that helps. I did not see anything for Python. Any suggestions?

  2. tyebud says:

    Great tutorial so far. I had one quick question. What modifications have you made to your perspective? I tried adding a console view to my right sidebar, but the only relevant option is the python console which doesn’t produce the same view as shown.

    Thanks again and keep up the great work!

    • admin says:

      I clicked and dragged the console over to the right side of the screen and it snaps in place. I think that is what you were looking for. Thanks for the nice comment

  3. Mindaugas says:

    Hello, very nice guide so far, but Im having some questions about setting this UI. I’ve got everything you showed in the video, installed, but its still not the same :) Id like Python to color my key-words and maybe a font and size like yours. So a bit more info on your settings would be just awesome.

  4. Mindaugas says:

    I dont know, maybe Im stupid, but I cannot setup it.
    After I did everything you showed in the video I just tried it and after hitting “Run” button I get:

    “Reference to undefined variable GOOGLE_APP_ENGINE”

    or some other crap, but I dont get result in the console.

  5. I says:

    Awesome tutorial, give us more!

  6. Frontware says:

    Great tutorials serie. We give it to our new programmer to get basic Python knowledge.

  7. James says:

    i need help with this wat do i need to fix

    # This program says hello and will ask for ur name.
    print(‘Hello who ever this may be!’)
    print(‘What is your name?’)
    myName = input()
    print(‘It is good to finally know your name, ‘ + myName)
    id apprieate ur help
    thank

  8. Remi Brisson says:

    HI Derek. Great tutorials. Very straight to the point and clear. One question: I’ve been working on IDLE up until now but want to switch to ECLIPSE as you make it look like it is so much better. I have Eclipse 3.7.2 downloaded and have PyDev installed. I have an issue with assigning the Python Interpreter though. An error pops up when I try to open my Python 2.5 executable. Is this too ld of a version for my version of Eclipse?

    Thx Remi

    • admin says:

      Thank you :) You should have at least Python 2.6 to use this tutorial. Make sure you have the most up to date version of Eclipse. I use Eclipse Classic 3.7.2. If you have any problems you probably need to update Pydev. Click on Help and Check for Updates to get the new version

Leave a Reply

Your email address will not be published.


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Switch to our mobile site