0% found this document useful (0 votes)
42 views

Working With The Class System in Python Chapter1

Uploaded by

Fgpeqw
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Working With The Class System in Python Chapter1

Uploaded by

Fgpeqw
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

DataCamp Object Oriented Programming in Python

OBJECT ORIENTED PROGRAMMING IN PYTHON

Intro to Object Oriented


Programming in Python

Vicki Boykis
Senior Data Scientist
DataCamp Object Oriented Programming in Python
DataCamp Object Oriented Programming in Python

What's Object-Oriented Programming? (OOP)

A way to build flexible, reproducible code


Developing building blocks to developing more advanced modules and libraries
DataCamp Object Oriented Programming in Python

Imperative Style and OOP Style


IMPERATIVE
our_list = [1,2,3]

for item in our_list:


print(f"Item {item}")

OOP
class PrintList:

def __init__(self,numberlist):
self.numberlist = numberlist

def print_list(self):
for item in self.numberlist:
print(f"Item {item}")

A = PrintList([1,2,3])
A.print_list()
DataCamp Object Oriented Programming in Python

All Python libraries work together


DataCamp Object Oriented Programming in Python

OBJECT ORIENTED PROGRAMMING IN PYTHON

Let's get started!


DataCamp Object Oriented Programming in Python

OBJECT ORIENTED PROGRAMMING IN PYTHON

Introduction to NumPy
Internals

Vicki Boykis
Senior Data Scientist
DataCamp Object Oriented Programming in Python

What's NumPy?

NumPy is a package for scientific computing in Python.

Uses matrices and vectors as data structures


Perfect for data science, where data is laid out in table-like formats
DataCamp Object Oriented Programming in Python

NumPy as a building block to Pandas


DataCamp Object Oriented Programming in Python

Creating NumPy arrays

Source: DataCamp
DataCamp Object Oriented Programming in Python

NumPy Array example

Example:

import numpy as np

our_array = np.array([2,3,4])
print(our_array)

[2 3 4]

print(type(our_array))

<type 'numpy.ndarray'>
DataCamp Object Oriented Programming in Python

Creating Multi-Dimensional Arrays

Example 1:

array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])

Example 2:

array([6, 7, 8])
DataCamp Object Oriented Programming in Python

OBJECT ORIENTED PROGRAMMING IN PYTHON

Let's practice!
DataCamp Object Oriented Programming in Python

OBJECT ORIENTED PROGRAMMING IN PYTHON

Introduction to Objects and


Classes

Introduction to Classes
Vicki Boykis
DataCamp Object Oriented Programming in Python

What is a class?
class PrintList:
A reuseable chunk of code that has
def __init__(self,numberlist):
methods and variables. self.numberlist = numberlist

def print_list(self):
for item in self.numberlist:
print(f"Item {item}")

A = PrintList([1,2,3])
A.print_list()
DataCamp Object Oriented Programming in Python

OOP Vocabulary
DataCamp Object Oriented Programming in Python

A Class is a template for an object


DataCamp Object Oriented Programming in Python

Declaring a Class

Declaring a class

class Dinosaur:
pass

# Used in Python 3, with/without parentheses


class Dinosaur():
pass

# Used in Python 2
class Dinosaur(object):
pass

An object is an instance of a class.

Tyrannosaurus = Dinosaur()
DataCamp Object Oriented Programming in Python

OBJECT ORIENTED PROGRAMMING IN PYTHON

Let's practice!

You might also like