Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

CPP – Intro to Python (1)

The document provides an introduction to Python, highlighting its significance in various fields such as data science, web development, and automation. It explains the fundamentals of Object-Oriented Programming (OOP) in Python, including class and instance definitions, methods, and inheritance. Additionally, it offers resources for further learning and emphasizes Python's ease of use and growing popularity.

Uploaded by

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

CPP – Intro to Python (1)

The document provides an introduction to Python, highlighting its significance in various fields such as data science, web development, and automation. It explains the fundamentals of Object-Oriented Programming (OOP) in Python, including class and instance definitions, methods, and inheritance. Additionally, it offers resources for further learning and emphasizes Python's ease of use and growing popularity.

Uploaded by

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

CPP – INTRO TO

PYTHON
Foundations
Why Python ?

Big Data / ETL / Algorithms Automation / Orchestration

Web
Data Analytic Scripting
Development

Solid Framework / Django


Download Python
◦ https://www.python.org/downloads/
What is OOP
◦ Known as Object Orientated Programming

◦ It is an efficient way to develop complex applications in a structured manner

◦ A method of structuring a program by bundling related properties and behaviours into individual objects

◦ General purpose, high-level, object-oriented programming language


◦ A dynamically typed language
◦ An interpreted language
◦ Is a portable language
◦ Runs on many types of Unix, including Linux and macOS, and Windows
What is OOP
◦ Object-Oriented Programming

◦ A programming paradigm using


◦ Classes and Objects
◦ Data Members/Attributes
◦ Methods
Python
◦ Has exception handling features, like Java, C#, Ruby, to make it easy to handle errors
◦ Has automatic memory management
◦ Has an extensive standard library

◦ Suitable for Rapid Application Development


◦ It supports multiple programming paradigms beyond object-oriented programming, such as
procedural and functional programming
◦ Can also be used as a scripting language
First, what is Python programming?

◦ 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 the body of the class is indented


◦In Python we use indentation to group statements in
the same block of code
Python 101 – Person class – An
Example
Class is the Template
Object is a Flavour of that Template
Methods are actions or Functions
performed by the object or class.
Python 101 – Person class – An
Example
◦ __init__ method is similar with the constructor in other languages (e.g. Java, C#)
◦ It initializes an instance with the provided arguments
◦ The first argument is the instance – it is passed in automatically when the method is called
◦ Ensure you don’t forget to specify that parameter!

◦ 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.)

Note that each method we declare within a class,


must have the first parameter reserved for the
instance
Python 101 – Using the Person class –
An Example (cont.)
◦Note that each method we
declare within a class, must
have the first parameter
reserved for the instance
◦When the method is called,
the instance is automatically
passed as the first argument
◦ i.e. we don’t have to provide an
argument for the first parameter
◦ e.g. p1.greetings()
Class and Instance Variables
◦ Instance variables
◦ When an instance/object is created it has its own distinct copy of the instance variables

◦ Class variables contain data shared by all instances/objects of a classs


Class and Instance Variables – An
Example
Class and Instance Variables
◦ Class variables contain data shared by all instances/objects of a classs
◦ Access a class variable either
◦ Via the class itself, OR
◦ e.g. Person.count
◦ Via an instance of the class
◦ e.g. self.count
Methods in Python (in an OOP context)
◦ Instance methods
◦ When the method is called, the instance is automatically passed as the first argument

◦ 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>

◦ e.g. class Student(Person):


◦ Student is the derived class
◦ Person is the base or super class
Inheritance – General Syntax
◦ Python supports multiple inheritance

class <DerivedClassName>(<BaseClass1>, <BaseClass2>,


…, <BaseClassN>):
<statement-1>

<statement-N>
◦ e.g. class Student(Person, Employee):
Resources
◦ Python
◦ https://www.python.org/downloads/
◦ https://docs.python.org/3.8
◦ https://docs.python.org/3.8/tutorial/controlflow.html
◦ https://realpython.com/python3-object-oriented-programming/
◦ https://realpython.com/python-basics/
Questions
Suggestions from here , spend some time every week
soaking up Python Tutorials, using project templates
to practice web Dev

Cheat Sheet Available on


Moodle today

You might also like