Giter Site home page Giter Site logo

acdick / dsc-1-06-05-classes-and-instances-lab-nyc-ds-career-031119 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from learn-co-students/dsc-1-06-05-classes-and-instances-lab-nyc-ds-career-031119

0.0 1.0 0.0 9 KB

Jupyter Notebook 66.51% Python 33.49%

dsc-1-06-05-classes-and-instances-lab-nyc-ds-career-031119's Introduction

Classes and Instances - Lab

Introduction

Okay, we learned how to declare classes and create instances in our last lesson. Let's put these new skills to the test!

Objectives

You will be able to:

  • Define classes
  • Instantiate instances of classes

Defining Classes

Let's define a Ride, Driver, and Passenger class as these are all crucial parts to a single ride. We have provided files for you aptly named ride.py, driver.py, and passenger.py where you can define the appropriate classes. Below, we import the classes from those files so we can use them in our code. The import syntax in Python is as follows: the keyword from followed by the name of the file then the keyword import and finally the name of the object we are importing (i.e. from [filename] import [object_name]). The first import is done for you, follow its example to import the other two classes.

Reminder: since we need to have some Python code in our class when we define it, we can simply write the keyword pass on the first line under our class definition

Note: the next cell imports an extension, autoreload, from IPython which reloads our import just before we execute our code, so that if we make a change in one of our files (i.e. ride.py), that change will be reflected below. Don't worry about it right now, but know that it is just updating our imported code. To run it, remove the below #s and run the cell. After running the cell, add the #s back before running your tests as the % operator will cause errors.

# %load_ext autoreload
# %autoreload 2
from ride import Ride
# import Driver class here
# import Passenger class here

Creating Instances

Let's now practice using our classes to make instances of those classes. Make two instances of the Passenger class and assign them to the variables meryl and daniel, respectively.

meryl = None
daniel = None
print(meryl, daniel)

Next, make one instance of the driver class and assign it to the variable, flatiron_taxi.

flatiron_taxi = None
print(flatiron_taxi)

Finally, make two instances of the Ride class and assign them to ride_to_school and ride_home.

ride_to_school = None
ride_home = None
print(ride_to_school, ride_home)

Summary

Great! In this lab, we were able to define multiple classes and create instances of those classes.

dsc-1-06-05-classes-and-instances-lab-nyc-ds-career-031119's People

Contributors

acdick avatar loredirick avatar mike-kane avatar peterbell avatar tkoar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.