Git Product home page Git Product logo

dsc-oop-recap-v2-1's Introduction

Object-Oriented Programming - Recap

Introduction

In this section, you learned about Object-oriented programming (OOP) as a foundational practice for software development and programming.

OOP overview

You now know all about OOP and how to define classes. Like functions, using classes in your programming can save you a lot of time by eliminating repetitive tasks. Classes go further than functions by allowing you to persist data. After all, class methods are fairly analogous to functions, while attributes add functionality by acting as data storage containers.

Class structure

As you saw, the most basic class definition starts off with:

class ClassName:

From there, you then saw how you can further define class methods:

class ClassName:
    def method_1(self):
        pass # Ideally a method does something, but you get the point
    def method_2(self):
        print('This is a pretty useless second method.')

You also learned about self. Specifically, that self is the default parameter used to define methods. This is necessary since instance methods implicitly pass in the object itself as an argument during execution.

Creating instances

Recall that after you define a class, you can then create instances of that class to bring it to life and use it! You're probably wondering what all of this has to do with data science. In turns out you'll use OOP principles when you start working with common data science libraries. For example, you might import the LinearRegression class from the scikit-learn library in order to create a regression model!

Remember, creating an instance of a class would look like this:

# Import class definition
from sklearn.linear_model import LinearRegression() 

# Create an instance of the class
reg = LinearRegression() 

Once you create an instance object of the class, you can then use all the methods associated with that class!

Level up

If you would like to dive deeper into OOP and learn some advanced topics, you can check out the additional OOP lessons and labs in the Appendix.

Summary

Congrats, you now have a solid foundation in OOP! You first learned how to define a class and methods. Then you learned how to create an instance of a class and define instance attributes. These skills will be useful for collaboration and writing concise, modular code!

dsc-oop-recap-v2-1's People

Contributors

cheffrey2000 avatar loredirick avatar mas16 avatar mathymitchell avatar sumedh10 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.