GithubHelp home page GithubHelp logo

python-oop's Introduction

Object Oriented Programming with Python

https://www.youtube.com/watch?v=Ej_02ICOIgs&ab_channel=freeCodeCamp.org

Notes

  • Classes should have the first letter as a capital

  • anything that starts with __ is called a "magic method"

  • you can assign value to parm by given a default value def __init__(self, name, price, qty=0):

  • to force a data type use : after varible name example def __init__(self, name: str, price: float, qty=0):

    • fact that we have assigned a default value of an int in qty tells python the date type it must use
  • assert keyword check what is happening to your expectations

  • asserts allow you to add better error handling easily

  • Class attributes are shared belongs to the class itself

  • instance attribute are only for the instance of that class

  • __dict__ all the attribute for Class level and instance level. This is useful for debugging

  • __repr__ is a magic method - representing your objects

    • it is best practise to name the items the same format as when you call the class return f"Item('{self.name}, {self.price}, {self.qty}')" = Item('Phone', 100, 5)
    • a special method used to represent a class's objects as a string.
  • image

  • @classmethod using this converts function into a class method

  • cls loads the class itself

  • @staticmethod static mehtod should do some work for you that has some logical connection to a class

    • a static method is bound to a class rather than the objects for that class
  • Parent and child classes

  • image

  • super functions allows us to use functionality from parent class

  • self.__class__.__name__ allows you to see the name of the class in a parent child situation

  • Encapsulation - describes the concept of bundling data and methods within a single unit

  • Decorators are like another function that you pre execute before another function

  • Puttig 2 __ infornt of a variable or attribute makes it a "private" atrribute

  • @property decorator makes things read only

  • @name.setter used t change variables that are read only

  • Encapsulation - Restricting directed action to attributes of program

    • using __
    • you don't allow access directly to an attribut you modify using a method
    • Check apply_increment and apply_discount functions
  • Abstraction - only show the nessary atrrib hide the unnessary details from users

    • hide unnessary info from instances i.e the email sending example
    • use __ double underscore to hide the functions \ methods
  • Inheritance - Inheritance is the capability of one class to derive or inherit the properties from another class.

    • Parent child stuff as above
  • Polymorphism - abilite to have diff scenarios The word polymorphism means having many forms. In programming, polymorphism means the same function name (but different signatures) being used for different types.

python-oop's People

Contributors

timwebster85 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.