Skip to main content

Command Palette

Search for a command to run...

Day 16: 100 Days of Code

Python

Updated
1 min readView as Markdown

Python Object Oriented Programming

Procedural Programming

In PP program executes from top to bottom.

Object Oriented Programming

We split larger task into smaller task. It models real world objects.

For instance: There is object waiter which has attributes(data) and also methods(functionality).

we create classes that are called blueprints. Then create objects to access their attributes and methods.

In the example below, we have imported python package where it has a class PrettyTable() . We then created object table for that class. So, that we can access its attributes and methods. add_column is the method of PrettyTable() class and align is the attribute of PrettyTable() class. We are here modifying the attributes and methods of PrettyTable() class.

from prettytable import PrettyTable
table = PrettyTable() 
table.add_column("Pokemon Name",["Pikachu","Squirtle","Charmander"])
table.add_column("Type",["Electric","Water","Fire"])
table.align = 'l'
print(table)
OUTPUT:
+--------------+----------+
| Pokemon Name | Type     |
+--------------+----------+
| Pikachu      | Electric |
| Squirtle     | Water    |
| Charmander   | Fire     |
+--------------+----------+

I have implemented coffee machine project in oop see on GitHub.