Giter Site home page Giter Site logo

dsc-classes-and-instances-lab-onl01-dtsc-sp-exp's Introduction

Classes and Instances - Lab

Introduction

Okay, you've 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

In this lab you will:

  • Create an instance of a class

Classes

You're about to create your first package 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 using:

# Import the entire file
import ride

# Import only the Ride class
from ride import Ride

In addition to ride.py file, we also created another file driver.py that contains the Driver class. Import this class in the cell below:

# Import only the Driver class

Create a Passenger class that doesn't contain anything in the following cell:

Note: By convention, you should use CamelCase to name the class. Also, you can't create an "empty" class. At the least, you need to specify the pass keyword to ensure the class definition is syntactically valid.

# Create Passenger class

Instances

Now practice using these classes to create instances. First, make two instances of the Passenger class and assign them to the variables meryl and daniel, respectively:

# Two instances of the Passenger class
meryl = None
daniel = None

print(meryl)
print(daniel)

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

# One instance of the Driver class
flatiron_taxi = None
print(flatiron_taxi)

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

# Two instances of the Ride class
ride_to_school = None
ride_home = None

print(ride_to_school)
print(ride_home)

Summary

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

dsc-classes-and-instances-lab-onl01-dtsc-sp-exp's People

Contributors

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

mkavalon

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.