Python Concepts Flashcards
Object Oriented Programming
Object-oriented programming is a programming paradigm that provides a means of structuring programs so that properties and behaviors are bundled into individual objects.
This type of programming utilizes objects and classes. Objects can contain both functions (or methods) and data.
An object provides a public interface to other code that wants to use it but maintains its own private, internal state.
Is Javascript an Object Oriented Programming Language?
Javascript is not a class-based object-oriented programming language. However, it does have ways of implementing object oriented programming. It just doesn’t strictly enforce compliance with OOP Principles.
It’s better known as a scripting language
You can implement OOP in JS by using objects, which contain properties and methods and support prototypal inheritance.
__proto__ property on objects can can be modified to refer to other prototypes
Object.create or the “new” keyword can be used to pass an argument to a prototype
ES6 also introduced the “class” keyword, but it’s just syntactic sugar over the existing prototyping technique. You can also implement subclasses.
4 Core Principles of Object Oriented Programming (OOP)
Abstraction
Encapsulation
Inheritance
Polymorphism
Python Class
Classes are templates used to define the properties and methods of objects in code.
They can describe the kinds of data that the class holds, and also how a programmer interacts with that data.
Class instances are created to implement design principles such as inheritance and encapsulation
Python Object
A python object is an instantiation of a class. It has both attributes and behaviors
Python Methods
Python methods are functions defined inside the body of a class. They are used to define the behaviors of an object.
Python Object Attributes
Attributes are defined in the class template and represent the state of an object
Abstraction
One of the 4 core principles of OOP
Abstraction - objects only reveal internal mechanisms that are relevant for the use of other objects, hiding unnecessary implementation code
Encapsulation
One of the 4 core principles of OOP
Encapsulation - wrapping data and the methods that work on that data in one unit.
Reduces software development complexity greatly and can help prevent accidental modification of data
Most of the time encapsulation can be achieved by creating classes with an overarching design structure that includes private and public methods (or getters and setters) for our systems to interact
Inheritance
One of the 4 core principles of OOP
Inheritance is one of the most important principles of object-oriented programming (OOP). It allows for one class (child class) to inherit the fields and methods of another class (parent class).
Polymorphism
One of the 4 core principles of OOP
polymorphism means having many forms
objects are designed to share behaviors but they can take on more than one form.
Polymorphism in Python allows us to define methods in the child class with the same name as defined in their parent class
Strongly Typed
Strong typing means that variables do have a type and that the type matters when performing operations on a variable
Dynamically Typed
Dynamically-typed languages are those (like JavaScript) where the interpreter assigns variables a type at runtime based on the variable’s value at the time
Scalar Types
scalar types have a finite set of possible values, and can be compared to other scalar values as equal, greater than or less than.
examples: int float True False None`
Collection Types
Collections in python are basically container data types
examples: Set List Tuple Dictionary