If you are brand new to Python, we recommend coming to the first meeting of the month which is First-Timers Night. You are welcome to come any week, but that first Thursday will always cater to beginners.
Python is a powerful and approachable programming language. It has an easy-to-learn syntax, which makes it an excellent language for beginners. Out of the box, Python is a powerful scripting language. It can be used to write all kinds of programs, from a simple tip-calculator to a fully-featured command-line Twitter client, or a program that automatically corrects your code for style consistency.
Additionally, the Python community provides a variety of tools for common applications. For web development, Django is a fully-featured web framework, similar to Ruby on Rails. It powers a lot of popular websites, including Pinterest and Instagram. There are also lightweight web framework options, like Flask.
Python is a big player in the science and data communities. The scipy family of libraries support a variety of science, math, and engineering applications, and scikit-learn is a popular Python library for machine learning. The natural language toolkit (nltk) is one of the best tools anywhere for parsing and analyzing natural human language. Python is a perfectly suitable language for writing code in the Hadoop Ecosystem, with packages like MRJob (Map Reduce Job) and Apache Spark.
Python is also the main user-programming language for the raspberry pi.
You can write and run Python programs on PCs, Macs, and Linux machines, so long as you have a Python interpreter installed. (On Mac and most Linux distributions, Python comes installed out-of-the-box.) See below for installation instructions on Windows.
You will also need a program to edit your code. While there are Interactive Development Environments (IDEs) for Python, we recommend starting with a regular text editor. SublimeText is a popular and powerful text editor that is available on all OSs. Notepad++ is also a nice option for Windows. We strongly recommend that you do not use a bare-bones text editor like Notepad on Windows or TextEdit on Mac for editing your code. These programs lack syntax-highlighting and have no support for plugins that can help you learn faster and be more productive.
- Open up a Command Prompt window.
- Windows: Start > Search > type in "
cmd
" > push 'Enter' - Mac:
Apple Button
+Space
> type in "terminal
" > push Enter - Ubuntu 14.04:
Ctrl
+Alt
+t
- Windows: Start > Search > type in "
- In the command prompt, type
python
and push Enter.- If a different prompt shows up, congratulations! You already have Python installed.
- If you got an error, follow the instructions below to install Python. It might look complicated, but this video shows that it can be done easily in under 3 minutes:
- If the
python
command gave you got an error, navigate your web browser to the Python downloads page and download the Python 3.5 file for your operating system. - Install Python to the default location (assuming you're running Windows,
C:\Python35
) - When the installation is complete, on your computer navigate:
My Computer > [System] Properties > Advanced [System Settings] > Environment Variables
- Under
System Variables
scroll down until you find the Variable calledpath
. Push theedit
button and add;C:\Python35;
to the end of thevariable value
field.- Note: This list is semicolon-separated. It will look like:
a;b;c;d;
, and you are just adding another item. There shouldn't be two semicolons next to each other.
- Note: This list is semicolon-separated. It will look like:
- Exit out of all Command Prompt windows, open a new one (
Start > Search > "cmd" > Enter
), typepython
then push Enter. - That's it! You've gotten over the worst part!
Python 3 introduced a lot of breaking changes, so even though it's been around for a decade, many people still use Python 2. There are still some popular libraries that don't support Python 3, but the vast majority do. We strongly recommend Python 3
Let's try saving a very basic program and running it.
- Open up the text editor that you downloaded earlier and type the following code into it. (If you copy and paste, Emma will be 😧. But seriously, it's a good idea to practice typing the code, so that you build muscle memory and get familiar with the code syntax.)
# hello_world.py
print('Hello, world!')
- Save the file as
hello_world.py
to the Desktop. - Open your terminal or cmd console, and run
cd Desktop
to navigate to your Desktop directory - For Mac and Linux, type
python hello_world.py
into the terminal. On Windows, just typehello_world.py
. Press enter to run your program, and the words "Hello, world!" should be displayed in your console. Amazing!
Here, we try a slightly more complex program that takes user input and makes use of a user-defined function called print_greeting
. (A function provides a reusable set of code steps, which can make use of input variables. For more information, check out the resources below!)
# greeting.py
# this is a function definition
def print_greeting(name):
greeting = 'Hello, ' + name + '!'
print(greeting)
# this executes the print_greeting function with the argument name = 'world'
print_greeting('world')
# input is a built-in function that takes input from a user's terminal
# use raw_input if you use Python 2
retrieved_name = input('Please enter your name')
print_greeting(retrieved_name)
Save this file as greeting.py
in your Desktop folder again. Follow the same steps as for the hello_world.py
program above to run greeting.py
.
We have collected beginner-friendly resources below to help you get started. If you need help choosing one, or have any other problems, the leads are here to help! Additionally, we encourage you to come to our weekly Thursday-night meetups to work collaboratively on projects or work through courses together.
- Code Academy 💻 🔰
- LearnPython.org 💻 🔰
- Learn Python the Hard Way 📚 🔰
- Interactive Python: How to Think Like a Computer Scientist 💻 🔰 📝
- Coursera: Programming for Everybody (Python) 🎒 📹 📝 10 weeks, 2-4 hours per week, next session begins June 1*
- Coursera: Intro to Interactive Programming with Python 🎒 📹 📝 5 weeks, 7-10 hours per week, project-based, next session begins May 22*
- ThinkPython 📚 📝
- Python for You and Me 📚
- Idiot's Guides: Beginning Programming 📚 💰 $19 paperback, $11 kindle
- MIT 6.00SC: Introduction to Computer Science and Programming 📹 📝
- Guttag, Introduction to Computer Science and Programming with Python 📚 📝 💰 $15 kindle, $20 paperback; goes with MIT OCW class above
- Invent Your Own Computer Games with Python 📚 example-based, teaches concepts by showing source code for a game and explaining the new python structures within
* Coursera materials are also available for use in independent study, outside of the session timeframes.
- 💻 - interactive courses or labs
- 📝 - problem sets or independent coding exercises
- 🎒 - fully-featured courses or classes
- 📹 - videos
- 📚 - books or long reads
- 📄 - articles or short reads
- 🔰 - tutorial style, guided
- 💰 - paid resource