The Ultimate Python Programming Tutorial

Python Programming tutorial for beginners. This Python Training Course Comes with Certification of Completion
4.2 (1,008 ratings)
Instead of using a simple lifetime average, Udemy calculates a
course's star rating by considering a number of different factors
such as the number of ratings, the age of ratings, and the
likelihood of fraudulent ratings.
22,335 students enrolled
70% off
Take This Course
  • Lectures 94
  • Length 6 hours
  • Skill Level All Levels
  • Languages English, captions
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works


Find online courses made by experts from around the world.


Take your courses with you and learn anywhere, anytime.


Learn and practice real-world skills and achieve your goals.

About This Course

Published 7/2012 English Closed captions available

Course Description

In this online Python course from O'Reilly Media, you will learn how to program with the popular development language. This tutorial is designed for the beginner, and you do not need to have any experience at all with programming or development in order to learn how to program with Python using this video tutorial.

Some of the topics that this course covers throughout the ultimate Python for beginners training include installing Python, data types and creating variables, input and output, decision making and repetition, iterators, list comprehension and functions. He also covers variable scope, modules - creating and using pre-built ones, object oriented programming, inheritance, exception handling and using data structures.

By the completion of this python for beginners video based training course on Python programming, you will be comfortable with Python and how to apply it to developing applications. Throughout the course you will apply what you learn in real-world examples, reinforcing what Mike is teaching you. Working files are included to allow you to use the same source material that the author does in this training course

Take this course now online Python course and master your skill!

What are the requirements?

  • A basic understanding of web design or fundamental programming skills

What am I going to get from this course?

  • To teach real programming skills that transfer to real life development
  • Build a solid understanding of Python Programming

Who is the target audience?

  • Web Masters, Programmers, Entrepreneurs

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.


Section 1: Introduction
Working Files - Download These First
What This Course Covers
Section 2: Installing Python
Installing Python In Windows
Installing Python On A Mac
Section 3: Writing Your First Program - Hello, World!
Entering And Running A Program In Windows
Entering And Running A Program On A Mac
Exercise 1
Section 4: Python Basic Data Types And Variables
Expressions, Statements, Variables
Working With Numbers
Working With Strings
Working With Booleans
Working With Lists
Working With Dictionaries
Working With Tuples
Exercise 1
Exercise 2
Section 5: Python Input/Output
Using The Print Function - Part 1
Using The Print Function - Part 2
Getting Input From The User
Exercise 1
Section 6: Making Decisions - if Statements
The Relational Operators
The Logical Operators
Simple if Statement
if-else Statement
if-elif Statement
Exercise 1
Exercise 2
Section 7: while Loops
Introduction To while Loops
Count-Controlled while Loops
Event-Controlled while Loops
Using continue
Using break
Working With Files - Part 1
Working With Files - Part 2
Exercise 1
Exercise 2
Section 8: for Loops
Introduction To for Loops - Part 1
Introduction To for Loops - Part 2
for Loops With Lists
for Loops With Tuples
for Loops With Dictionaries
for Loops With Files
Exercise 1
Exercise 2
Section 9: Iterators
Understanding Iterators
Using iter And next
Iterators And Dictionaries
Other Iterators
Exercise 1
Section 10: List Comprehensions
Introduction To List Comprehensions
Using List Comprehensions With Files
Exercise 1
Section 11: Functions
Introduction To Functions - Why
Defining Functions
Calling Functions
Functions With Multiple Arguments
Predicate Functions
Exercise 1
Exercise 2
Section 12: More On Functions
Recursive Functions - Part 1
Recursive Functions - Part 2
Function Objects
Anonymous Functions
Higher-Order Functions
Exercise 1
Exercise 2
Section 13: Scope
Global Scope
Local Scope
Nested Scope
Exercise 1 - Part 1
Exercise 1 - Part 2
Section 14: Modules
Using Built-In Modules
User-Defined Modules - Part 1
User-Defined Modules - Part 2
Module Namespaces
Exercise 1
Section 15: Object-Oriented Programming - Part 1
Abstract Data Types
Designing A Class, Fields And Constructors
Designing A Class, Methods
Data Structure For Fields
Exercise 1
Exercise 2
Section 16: Object-Oriented Programming - Part 2
Creating A Derived Class - Part 1
Creating A Derived Class - Part 2

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

Infinite Skills, High Quality Training

Infinite Skills is a Canadian based company who offer a huge and ever growing range of high quality eLearning solutions that teach using studio quality narrated videos backed-up with practical hands-on examples and comprehensive working files. All courses are created by trained educators and experts in video based education.

The emphasis is on teaching real life skills that are essential for progressing in today's commercial environment.

Ready to start learning?
Take This Course

Crafting Great Python APIs


Good libraries are like novels -- hard to write in any language. Every language has a different definition of good. Java can't be transliterated to Pythonwell because every language has its own idioms.
"Pythonic" code is in harmony with standard libraries and conventions of Python and takes advantage of the features baked into Python. You might not think you create APIs -- you do, if only for your future self. Anywhere you present functionality to other code, even in the same codebase. Your function names, classes, command line flags, HTTP endpoints, and error messages are all part of your API.
To build a library that's easy to use, you have to put yourself in the shoes of a developer who heard about your library this morning and has a problem to solve this afternoon. Don't make them put aside all they know already. Use familiar vocabulary in your API. Reuse conventions from the rest of Python. Try to avoid surprising them with anything.

The Meaning of Craft

Craft is any process that attempts to create a functional artifact without separating design from manufacture. -- Wroblewski source

As you build your library, you will likely see rough spots that need improvement. That's normal -- try to smooth them out as they become visible instead of promising to clean it up later. Think about how your decisions will affect the finished product. Is naming this method requests.requests_get going to make it easy to remember? No, it looks confusing since you're already in a namespace. For more about simplicity and readability, take a minute to review The Zen of Python (PEP 20).

Small Considerations

Name Well

Names make code readable, it's how users most often will be thinking about your library. Avoid names like "skycopter" -- what even is that? Names need to be easy to reason about. If the name that best describes your object or function is exceptionally long, consider that it may have too many responsibilities and will be too complicated for users to understand easily. This is doubly true if it contains the name of one or more design patterns .
Use familiar words if you can. Requests has methods that match HTTP method names, which users of requests likely know already.

Function Arguments

The average human can hold five to nine chunks of stuff in their head at once; don't fill up all those slots with just your function call. If you have that many knobs on your widget, fear not. You can make sane defaults, use a configuration file, or add a wrapper class so developers don't need every parameter for every call.
Say you have a function that looks up a user on your service by their username: that requires API credentials, an API endpoint, and a user to query for.

get_user(api_user, api_token, endpoint, username):
     """Do some things to get user info"""

class Session(object):
     def __init__(self, user, token, endpoint=""):
         self.user = user
         self.token = token
         self.endpoint = endpoint

     def user(name):
        return get_user(self.user, self.token, self.endpoint, name)

So which would you prefer to call -- get_user or Session.user? I'd prefer not to provide the arguments every time, and a class is one way to do that. Another alternative is to use functools from the standard library. A "partial" is a function that remembers some provided arguments and calls the underlying implementation.

import functools
query_user = functools.partial(get_user, user, token, endpoint)

The code above saves the first arguments to get_user and gives back a new function that only needs to be passed the username similarly to the Session class. The difference is that functools lets us skip the boilerplate code to create the object.

Magic Methods

Python has loads of standard method names associated with defined protocols. Most of them are made to integrate your objects with builtins -- think len and str. To let your object use those builtins you simply need to implement __len__ and __str__. If you find yourself writing a method like .length() ask yourself if thats what users would expect. The answer is likely "No!"

__repr__ methods

When you make an object, also define a nice __repr__ function for it -- you'll thank yourself later. By default, when you print an object, Python tells you about its location in memory.

>>> print(r) # Less helpful
< requests.models.Response object at 0x7fa4fedfbb50 >

Two lines of code are all it takes to make printing an object useful.

class Response(object):
     def __repr__(self):
         return "< Response [%s] >" % self.status_code
print(r) # Way better!
# < Response [200] >

This may not seem like much of a change, but for users new to your library or those that are using it interactively this is a huge improvement. It makes it easy to see what an object is without knowing all the fields it provides.

Generators -- A Different Way of Iterating

When you present a user with a list, you must consider their needs. Are you presenting the filename of every file on their filesystem as a list; loading every item into memory at once? If you can calculate the values incrementally, it's helpful to do so. It means you can start processing values without waiting for the full list to be loaded into memory. Consider looping over a bunch of numbers.

for i in range(1000):

In Python 2, that code would create a list of all 1000 digits and returned it to be iterated over. It works, but using all that memory doesn't help the caller. The caller only needs to know the next value. In Python 3, range would generate the next number only when asked. Generators are iterable, but don't produce all their values up front.
Here, we make our own generator to count up from zero.

def counter(maximum):
     count = 0
     while count < maximum:
         yield count
         count += 1

What makes a generator different from a normal function is the yield keyword. The function stops what it's doing at the yield and hands control back to whatever called it. This lets the caller (our for loop) process each result before calculating the next value. For our generator, counting to 5 million would have the same memory footprint as counting to four.

Initializing Your Library

It's easy to add setup steps for your classes in the __init__ method, but failures might leave you with some resources that need to be cleaned up. Lockfiles, open sockets, and other things need to be cleaned up whether your object finished creating or not.

a = Connection(url, port, user, pass)
     a.connect()"some data")
     print("Uhoh, something went wrong!")

It's easy to forget to release all your resources. Python provides context managers to make the process of acquiring and releasing shared resources easier. A context manager is a simple way to ensure that initialization and teardown are easy to do correctly. To use a context manager, you open a block using the with statement and teardown is automatically done when exiting the block.

import contextlib

# library code
def connection(url, port, user, pass):
     c = Connection(url, port, user, pass)
     yield c

# calling code
with connection(url, port, user, pass) as a:
     # the connection is initialized here"some data")
     # at the end of the block, the connection is closed automatically

The calling code can be much simpler thanks to with. You can also see that the contextmanager is actually a decorator atop a generator function. See how nicely these compose? Context managers are useful for safely writing to files, getting transaction locks, database connections, and more.

Think Usability

Developers are people too. When I buy a power tool, I don't read the warnings. After a trip to Ikea, I don't read the instructions unless I have to. Your program is a tool, and its job is to help users. Your users want to install a library and get back to work, and a great user interface is critical to letting them do just that.

What's Up Doc?

Where is your documentation? I hear you, documentation isn't code, but it is the Application-Human Interface for your project. Without documentation you leave developers adrift on StackOverflow -- or worse, send them wading through your source code never to be seen again.
For an example of nice documentation, take a gander at the tox or sphinx docs. Both prominently feature a low-jargon description of the project. Here's the Sphinx summary:

Sphinx is a tool that makes it easy to create intelligent and beautiful documentation

And on tox's page:

tox aims to automate and standardize testing in Python

A curious developer might then say "neat, how does this tool do that?" Both pages answer immediately with code samples and feature highlights. In just a minute or two I can decide whether these are the right tools for my job.
Further down the page, there are paragraphs of additional detail and links to: extra examples, documentation, user stories, and feature lists.
For a deeper dive into documentation, check out Django contributor Jacob Kaplan-Moss' series on Writing Great Documentation. It ought to be required reading for Computer Science students. William Zinsser's book On Writing Well is an excellent guide for any nonfiction, but does not focus on technical documentation.

Exceptions and Errors

Computers break. Assumptions can be wrong. The International Space Station has six computers running all the time, checking each others' work. In space, every calculation must be correct every time. When things break in (or outside of) your library, which of these should you show?

ERROR: Data failure
ERROR: Could not save data to /opt/myapp/data.txt, permission denied

Your error messages need to be as helpful as possible. They are born to say "______ went wrong, and here's how you make it stop _____". You may not be able to depend on being able to surface logs directly, but you can always be sure to throw readable exceptions. It's a good idea to create your own exception classes, check out this example from SQLAlchemy (full code).

class SQLAlchemyError(Exception):
     """Generic error class."""
class DisconnectionError(SQLAlchemyError):
     """A disconnect is detected on a raw DB-API connection.
     This error is raised and consumed internally by a connection
     pool. It can be raised by the :meth:`.PoolEvents.checkout`
     event so that the host pool forces a retry; the exception will
     be caught three times in a row before the pool gives up
     and raises :class:`~sqlalchemy.exc.InvalidRequestError`
     regarding the connection attempt."""

Having a top-level class for all SQLAlchemy's exception classes makes it easy to see if a problem comes from SQLAlchemy with an issubclass test. For users, this makes it easy to track down the source of a problem.
Specific exceptions like DisconnectionError help by explaining everything SQLAlchemy tried before raising the exception.

Wrapping Up

Next time you sit down to write a library, don't start by writing code. Get out of the author mindset for a moment and think about how you'd expect it to work. Consider which features you'd need, and which are "nice-to-have". Look at libraries that solve similar problems and see what idioms they use, or what they do that doesn't seem quite right.
Take the time to solve the problem you set out to in the best way you know how. Your users and fellow developers will thank you.