Learn Python

Logo color python f20cfa11c8fbcd362baecc08c6f5fa9ec2989ba61cccee601b8e3b967e1b3496

Python is a versatile language used in a variety of applications from web development to machine learning. This page will get you up to speed on the basic syntactical elements of the language.

Write Python in 5 Minutes

Let's start writing Python by using the simple interpreter. We can print output to the terminal by using the print command. Let's print out the integer 42. Try typing:

print 42.

Watch videos and take more challenging quizzes below.

Great! Python also uses strings, which are characters wrapped in double quotes. Let's print out your name! Try:

print "[your name]"

Learn more about Python's data types below.

Fantastic! Let's try a more advanced technique called list comprehensions to show how powerful Python can be. Don't worry if you don't understand it, yet! Let's count from 1 to 10! Try typing:

print [x+1 for x in range(10)]

This is a more advanced technique, but you can learn more about for loops below.

Amazing! Another powerful technique is to encapsulate pieces of reusable code into procedures (or functions). We've introduced a function that you can call by running:

hello()

Learn more about procedures below.

Final step! Classes are powerful and fundamental concepts to object-oriented programming. They can also contain methods and properties, which can also be procedures!

Run the last command to enter the classroom!

Classroom().enter()

Or, stick around and watch videos about classes below.

python>

Icon valid 826d148495b5175591fad4986dc043861d8693713ecccf2a656f365bcdb50d7f

Success!

Printing, Variables & Arithmetic

Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Printing & Arithmetic
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Variables
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Variables can Vary

Data Types

Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Strings
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Strings & Numbers
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Indexing Strings
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Lists
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Nested Lists
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Dictionaries
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Using Dictionaries

Conditional Statements

Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
If Statements
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Or

Loops

Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
While Loop
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Break Statement
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
For Loop

Procedures

Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Intro
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Using Procedures

Classes

Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Definition of Classes & Methods
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Classes vs. Functions
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Defining a Class I
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Defining a Class II
Icon checkmark white 5c349694188d93e550235390d97e5f3e7cbce2c1113de846cd7c786bf98960ff
Defining init

Useful Resources

Just Python

Learn Python the Hard Way

A free online book by Zed Shaw. It's written for novice programmers looking to learn Python. It's organized by topic and has very good explanations and example code throughout. Each section ends with helpful 'Study Drills.'

Python Wiki

This reference might be overwhelming, but it has links, links and more links on everything Python.

Libraries & Frameworks

Flask

Flask is a micro web development framework. It's simple to learn, easy to understand, and well-documented. It's great for small to medium sized projects.

Django Framework

Django is a free and open source high-level web framework for Python that is commonly used in Python applications.

Developer Tools

iPython and iPython Notebook

A web-based interactive computational environment that combines code execution, text, mathematics, plots and rich media in a single document.

Python Tutor

A tool to help visualize and walk through source code.

Communities

Python Hackers

Share your Python projects with other enthusiastic developers.

StackOverflow

This is where to ask specific code-related questions if you’re ever stuck on a problem.

Code Tricks & Examples

Python Code Snippets

A focal point for snippets of Python code that can be used (and reused) for various purposes.

Popular Python Recipes

More code examples to perform specific tasks and various snippets for whatever you might need.

Fun & Practice

Project Euler

This site provides a lot of highly mathematical problems which can be solved with programming. It's a good place for building your 'Procedural Thinking'.

Python Problem Sets

Practice opportunities from the organization that manages the Python language. Some are better than others.

Useful Articles
Cheatsheets

Python Glossary

A list of commonly used Python terms and their definitions.

Hyperglot

A side-by-side reference of Python syntax vs other scripting languages.

Icon globe e82eae5d45465aba4fbe4bb746905ce55dc3324f310b79c60e4a20089057d347

Udacity 现已提供中文版本! A Udacity tem uma página em português para você! There's a local version of Udacity for you! Sprechen Sie Deutsch?

Besuchen Sie de.udacity.com und entdecken Sie lokale Angebote, unsere Partnerunternehmen und Udacitys deutschsprachigen Blog.

前往优达学城中文网站 Ir para a página brasileira Go to Indian Site Icon flag de deedb1a7a695700236cb6ef4204ddbede5d197dab9b47716c87a0b4d5d9fc325 Zu de.udacity.com continue in English