Coder Social home page Coder Social logo

dsc-classes-and-instances-lab-dc-ds-060319's Introduction

Classes and Instances - Lab

Introduction

Okay, you'lve learned how to declare classes and create instances in the last lesson. Now it's time to put these new skills to the test!

Objectives

You will be able to:

  • Define classes
  • Instantiate instances of classes

Defining Classes

You're about to create your first packages with class definitions! You've already seen how to import packages such as NumPy and pandas, and you can organize your own code in a similar manner. For example, once you define the ride class in a file ride.py you can then import said code in another notebook or script with import ride.

So without further ado, create three files in this folder: ride.py, driver.py and passenger.py. In each of these, define an accompanying class. By convention, you should capitalize the names of these classes within the .py file. For example, in the ride.py file, define a Ride class. For now, the classes need not do anything, just write the keyword pass on the first line under each of your class definitions.

from ride import Ride
# import Driver class here
# import Passenger class here

Creating Instances

Now practice using your 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, you were able to define multiple classes and create instances of those classes.

dsc-classes-and-instances-lab-dc-ds-060319's People

Contributors

peterbell avatar loredirick avatar mike-kane avatar mathymitchell avatar tkoar avatar

Watchers

James Cloos 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.