Through our research and collaboration with our industry partners, Make School has decided to focus on four core languages.
- Python - For computer science, data science, and whiteboard coding.
- Swift - For mobile iOS development
- Ruby - For backend API and web development
We use Python for our computer science courses because of its beautiful and elegant syntax, its wide-spread use across finance, data science, and web development, and because of its classical, object-oriented structure.
Complete Try Python (2 hours), a gentle introductory tutorial to the language with fun videos.
HackerRank Python Challenges
Hacker Rank is a fantastic tool to drill coding and algorithmic problem solving. HackerRank will automatically test all your code submissions for correctness.
Create an account and complete all the challenge sets:
- Introductory Challenges (1 hour)
- Basic Data Types (1 hour)
Intro to OOP - 6 Videos
Settle in and get ready for some more videos :D - Watch these 6 videos for Python OOP Tutorials by Corey Schafer.
Pay attention to the following words and how they are used:
- Class Variables
- Static Method
- Class Methods
- Instance method
Intro to OOP - Hands On
Object-Oriented Programming is a common and useful coding paradigm, one way to organize code and code's functionality. Object-Oriented programming is best understood through examples of classes. (This example is taken from An Introduction to Classes and Inheritance by Jess Hamrick)
Let's look at a Pet class written in python. Open your terminal and create a file called
pets.py and then open it in atom.
$ touch pets.py
$ atom pets.py
Now copy and paste the following code the file called
pets.py and save it with the keyboards shortcut Command+S.
def __init__(self, name, species):
self.name = name
self.species = species
return "%s is a %s" % (self.name, self.species)
Now let's look at how this code will work if we want to create some instances of the Pet class in the command line. Open your terminal in the directory where
pets.py lives and type
python to begin a python REPL. Now try the following code in the python REPL.
# Polly the Parrot
>>> from pets import Pet
>>> polly = Pet("Polly", "Parrot")
>>> print polly
# Ginger the Cat
>>> ginger = Pet("Ginger", "Cat")
>>> print ginger
# Clifford the Dog
>>> clifford = Pet("Clifford", "Dog")
>>> print clifford
Now let's add two Subclasses to Pet called Dog and Cat. These subclasses Inherit from their Superclass Pet. Add the following two subclasses to the
def __init__(self, name, chases_cats):
Pet.__init__(self, name, "Dog")
self.chases_cats = chases_cats
def __init__(self, name, hates_dogs):
Pet.__init__(self, name, "Cat")
self.hates_dogs = hates_dogs
Let's see how these work now
>>> from pets import Pet, Dog
>>> mister_pet = Pet("Mister", "Dog")
>>> mister_dog = Dog("Mister", True)
>>> isinstance(mister_pet, Pet)
>>> isinstance(mister_pet, Dog)
>>> isinstance(mister_dog, Pet)
>>> isinstance(mister_dog, Dog)
Now create a bunch of cats and dogs.
>>> from pets import Cat, Dog
>>> fido = Dog("Fido", True)
>>> rover = Dog("Rover", False)
>>> mittens = Cat("Mittens", True)
>>> fluffy = Cat("Fluffy", False)
>>> print fido
>>> print rover
>>> print mittens
>>> print fluffy
>>> print "%s chases cats: %s" % (fido.getName(), fido.chasesCats())
>>> print "%s chases cats: %s" % (rover.getName(), rover.chasesCats())
>>> print "%s hates dogs: %s" % (mittens.getName(), mittens.hatesDogs())
>>> print "%s hates dogs: %s" % (fluffy.getName(), fluffy.hatesDogs())
Can you answer the following questions:
- What is a 'class'? What is an example of a class besides pets and dogs and cats?
- How are classes used in OOP?
- What is 'inheritance'? What is an example of inheritance?
Make School's OOP Challenge
Complete Make School's OOP Coding Challenge (1-2 hours)
If you have feedback on this tutorial or find any mistakes, please open issues on the
GitHub Repository or comment below.