I 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 [googleplusone] 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
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?
I use the classic version of Eclipse. To program in Python with Eclipse you need to install a module called Pydev. I go into how to install that in this article and video
Hi Derek how are you? Sorry if I’m a little thick headed but I’m watching you setting up your Python environment in eclipse and you rushed through it saying ok ok ok but I feel its very important to let novices like myself know and learn how to properly setup things in eclipse, heck that’s a small tutorial in itself working with eclipse. You know stuff like knowing how ti import libraries and short cuts that eclipse has. Anyways bud that’s for your great work I appreciate it
Thank you 🙂 I’ll look into making an Eclipse tutorial because I’ve been getting these messages a lot. I think it is because the new version of Eclipse (Juno) is buggy and the plugins aren’t working. Definitely stick with Indigo. I’ll see what I can do with the tutorials, but it seems to be a windows issue and I only have a mac and linux machine
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!
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
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.
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.
Awesome tutorial, give us more!
Thanks 🙂 I have a ton of Python 3.0 and 2.7 tutorials. I hope you find them useful
Great tutorials serie. We give it to our new programmer to get basic Python knowledge.
Wow, that’s very cool. I’m glad you have found it to be so useful
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
print “Hello who ever this may be!”
myName = raw_input(“What is your name? “)
print “It is good to finally know your name, ” + myName
I hope that helps
thank alot man 😀
You’re very welcome
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
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
Hi Derek i’ve in and out this site for quite some time.Until now with you’re instruction i’ve been able to hadle most of my projects.Today i’m trying to learn some python, but when installing pydev, i get the same error over and over connection to to fetch jars has timed out.i’ve tried everything.please help 😀
Are you on a Mac or PC? Do you have Eclipse Indigo installed? That is the newest version of Eclipse
I do have it, I’m on windows 7.
Are you trying to install from inside of Eclipse? If so, that goes crazy every once in awhile. Try downloading Pydev directly here pydev.org/download.html
Online I found this solution that everyone says works
I had the same problem. And found solution on russia site. In file eclipse.ini under line -vmargs add this line:
-Djava.net.preferIPv4Stack=true
This will resolve problem.
I hope that helps
Sorry for being annoying and at all, but I keep getting this:
An error occurred while collecting items to be installed
session context was:(profile=SDKProfile, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=).
Unable to read repository at.
Read timed out
Unable to read repository at.
Read timed out
Unable to read repository at.
Read timed out
Unable to read repository at.
Read timed out
Unable to read repository at.
Read timed out
Tried everything I found online and What u said.
No problem. Have you tried these:
1. Help->Install New Software”, click on “Available Software Sites”, disable all websites whose URL is like “*.oracle.com/*”
2. Some people are having trouble on PCs if they are using Java 7. Try downgrading to jdk6
Well I didn’t find any oracle.com links in my eclipse.Got it to Java 6 Still same error.
Sorry, but I don’t know what else to try? I’m sure you have tried a full re-install right?
Yea a couple of times.
This is incredible. 😀
I find this tutorial frustrating.
You show the code in clear, basic terms, but you assume we can install the software and plugins and updates ?
I tried for half hour to get started on this and I am getting no where.
I downloaded eclipse classic and I installed the pydev software via eclipse, but eclipse doesn’t recognise the python interpreter.
I am using eclipse 4.2.0 and the latest version of python 3.2.3. I also tried python 2.7.3, no to avail.
I’m bailing.
I’m sorry it didn’t work for you. You need to use Python 2.7. Python 3 won’t work and I have a tutorial on Python 3. Many things have changed since I made this and the Pydev plugin is now a little buggy. Sorry about that
Hi. Thank you very much for your awesome tutorials. I would request you if it is possible for you to make a video on F2Py. Specially on calling fortran programs from python and make gui on top of it. It is a very interesting topic on scientific community now a days so that they can use their old fortran code with an interface.I highly appreciate your effort in making python Tutorial.
Thank you 🙂 I’ll check that out. Thank you for the request
Can you show me how to code toontown online?
I’m going to be making a bunch of games for Android devices very soon. I’ll cover most every genre. Because everything will be written in Java, all of the games will work on any desktop as well. I hope you enjoy them. To get a head start check out my Java tutorials
I am having trouble installing the PyDev module. I typed in pydev.org after going to help>install new software. But, nothing comes up.
Click Help > Install New Software in Eclipse
Click Add Site Button
In popup type Pydev and Pydev Extensions in name
type in Location
Check both Pydev updates. You may have to uncheck Contact all update sites during install to find required software, but try it with it checked first.
Hit Ok a bunch of times
Tell me if that didn’t work
Hey Derek how are you? Is there anyway you can convert your python Tuts into HD? Can’t see it clearly and by any chance my friend do you know Ruby and Ruby on rails?
Thanks Bud
Sorry, but I recorded them in 720p years ago and there is no way to record them in 1080p. YouTube used to limit the size of your videos back when I made those. Yes I know Ruby and will cover it, but at the moment I’m working toward making Java / Android Games and Apps. I may slip a Ruby tutorial in though because I really want to cover it. Thank you for the request 🙂
Hi Derek, it took some trial and error getting PyDev working on Windows 7 inside of Eclipse Indigo, but I am up and running. I notice on “Python 2.7 Tutorial Part 2” as you type… some auto-complete looking sub-menu appears. How does one activate that feature?
Windows > Preferences > PyDev > Editor > Content Assist > Advanced
That should work
hey Derek,
I’ve installed eclipse and pydev as per your instruction.
I then began your tutorial #1. but when I “run” the console displays only:
Finding files… done.
Importing test modules … done.
———————————————————————-
Ran 0 tests in 0.000s
OK
Derek? What am I doing wrong?
Try running using Run Configurations instead of Run
Hi Derek
I very much enjoyed tutorials/ My Question is this on the first video setting up the python pyDev on Eclipse I am pleased to say I had no problems. The only thing is the folder you put all your work in how should you name the folder and where should you put the folder so I can follow your python tutorial 2.7 or which file path should I specify for python 2.7.
Thanks a lot
D Calder
Hi Derick,
The name of the folder is up to you. There isn’t really any rule for that. It is normally best to create the folder in your Documents folder, but that is up to you. The only issue to look out for is to make sure you have permission to execute from that folder. I hope that helps 🙂
Hi Derek
I went back on eclipse and I found this in the console
Finding files… done.
Importing test modules …
done.
Thanks very much
D A Calder
Hi Derek
Every thing is working know I had to do lot of trouble shooting
with the configuration Run and for the Run in the tool bar.
Thanks again for your tutorials
Derick Alphonso Calder
PS Great
Great I’m glad you got it fixed 🙂
you are a genius derek seriously
Thank you, but I promise you that I’m not that smart 🙂
HI Derek
Just an update I am following Your Other Tutorials on PHP, JavaScript. HTML CSS and python.
Thanks Again from
Derick Calder
PS Great Great Tutorials
Thank you very much 🙂
Hello Derek,
I have been wanting to learn Python for quite a while and have been looking for a group of videos and found yours. I really appreciate the time and effort you put into making them. My only complaint is with using Eclipse. I spent many hours going over documentation to try and get the thing working properly. I still can’t get the console to work. It would be really helpful for us beginners if you would have a video about using Eclipse. It has been the most frustrating time I have ever experienced with any program.
Hello Wayne
I’m going to make a series of tutorials set around teaching languages in 1 30 minute video. I’ll see what I can do about Eclipse. I know it can be frustrating.