CPP – Intro to Python (1)
CPP – Intro to Python (1)
PYTHON
Foundations
Why Python ?
Web
Data Analytic Scripting
Development
◦ A method of structuring a program by bundling related properties and behaviours into individual objects
◦ Python is a high-level programming language used for general-purpose software engineering. It’s a server side language –
which means it runs on the server, and is responsible for processing the logic behind user inputs, interacting with databases
and other servers, etc.
◦ Initially developed in the late 1980’s by Guido Van Rossum, Python has been around for decades alongside other server side
languages like Java and C. Van Rossum modeled Python after the English language, eliminating unnecessary syntax to make
it easier to read and write than other programming languages.
◦ Python is an open-sourced language like Java (our other fave programming language), and in recent years has increased in
popularity due to its use in data science. Python also has a strong community around machine learning, data modeling, data
analysis and artificial intelligence (AI), with extensive resources and libraries built for these purposes.
◦ And yes, the rumors are true. Python is named after the British comedy group Monty Python.
◦ Indeed if you decide to learn Python, you shall code with the strength of many men, Sir Knight.
Why Python
◦ Just to name a few, Python is used in Data Mining, Data Science, AI, Machine Learning, Web
Development, Web Frameworks, Embedded Systems, Graphic Design applications, Gaming, Network
development, Product development, Rapid Application Development, Testing, Automation, the list
goes on.
◦ Python is used as an easier and more efficiently-written alternative to languages like C, R, and Java,
and is growing in popularity as the primary language for many applications.
What types of companies use Python?
Websites built with Django / Python
◦ https://djangostars.com/blog/10-popular-sites-made-on-django/
Learning
◦ https://www.w3schools.com/python/
◦ Great Resources
◦ https://www.geeksforgeeks.org/
Python 101 - Class Definition Syntax
source: https://docs.python.org/3.8/tutorial/classes.html
◦ Note that each method we declare within a class, must have as the first parameter the instance
◦ When the method is called, the instance is automatically passed as the first argument
Creating (Instantiating) a Person
Creating (Instantiating) a Person
◦ Output
Emma
28
Python 101 – Person class – An
Example (cont.)
Python 101 – Person class – An
Example (cont.)
◦ Class methods
◦ Defined using @classmethod
◦ When the method is called, the class is automatically passed as the first argument
Methods in Python (in an OOP context)
(cont.)
◦ Static methods
◦ Defined using @staticmethod
◦ Only use static methods if you have to implement some functionality related to the class, but you don’t need to
access the instance (i.e. self)or the class (i.e. cls) within that method!
Inheritance – An Example
Inheritance – General Syntax
class <DerivedClassName>(<BaseClassName>):
<statement-1>
…
<statement-N>