Intro to Object Oriented Programming in P y thon W OR K IN G W ITH TH E C L ASS SYSTE M IN P YTH ON Vicki Bo y kis Senior Data Scientist
WORKING WITH THE CLASS SYSTEM IN PYTHON
What ' s Object - Oriented Programming ? ( OOP ) A w a y to b u ild � e x ible , reprod u cible code De v eloping b u ilding blocks to de v eloping more ad v anced mod u les and libraries WORKING WITH THE CLASS SYSTEM IN PYTHON
Imperati v e St y le and OOP St y le Imperati v e 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() WORKING WITH THE CLASS SYSTEM IN PYTHON
All P y thon libraries w ork together WORKING WITH THE CLASS SYSTEM IN PYTHON
Let ' s get started ! W OR K IN G W ITH TH E C L ASS SYSTE M IN P YTH ON
Introd u ction to N u mP y Internals W OR K IN G W ITH TH E C L ASS SYSTE M IN P YTH ON Vicki Bo y kis Senior Data Scientist
What ' s N u mP y? N u mP y is a package for scienti � c comp u ting in P y thon . Uses matrices and v ectors as data str u ct u res Perfect for data science , w here data is laid o u t in table - like formats WORKING WITH THE CLASS SYSTEM IN PYTHON
N u mP y as a b u ilding block to Pandas WORKING WITH THE CLASS SYSTEM IN PYTHON
Creating N u mP y arra y s So u rce : DataCamp WORKING WITH THE CLASS SYSTEM IN PYTHON
N u mP y Arra y e x ample E x ample : import numpy as np our_array = np.array([2,3,4]) print(our_array) [2 3 4] print(type(our_array)) <type 'numpy.ndarray'> WORKING WITH THE CLASS SYSTEM IN PYTHON
Creating M u lti - Dimensional Arra y s E x ample 1: array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14]]) E x ample 2: array([6, 7, 8]) WORKING WITH THE CLASS SYSTEM IN PYTHON
Let ' s practice ! W OR K IN G W ITH TH E C L ASS SYSTE M IN P YTH ON
Introd u ction to Objects and Classes W OR K IN G W ITH TH E C L ASS SYSTE M IN P YTH ON Introd u ction to Classes Vicki Bo y kis
What is a class ? class PrintList: A re u sable ch u nk of code that has methods and v ariables . 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() WORKING WITH THE CLASS SYSTEM IN PYTHON
OOP Vocab u lar y WORKING WITH THE CLASS SYSTEM IN PYTHON
A Class is a template for an object WORKING WITH THE CLASS SYSTEM 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() WORKING WITH THE CLASS SYSTEM IN PYTHON
Let ' s practice ! W OR K IN G W ITH TH E C L ASS SYSTE M IN P YTH ON
Recommend
More recommend