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

0001 Introduction To Python

Uploaded by

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

0001 Introduction To Python

Uploaded by

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

INTRODUCTION TO

PYTHON
PROGRAMMING
Week 1
BACKGROUND
• Python is a high-level, interpreted programming language that is widely used for web
development, data analysis, artificial intelligence, and scientific computing. It is a versatile
language that is easy to learn and can be used for a wide range of tasks.
GUIDO VAN ROSSUM
• Guido van Rossum is a Dutch programmer and the creator of the Python programming
language. He started working on Python in 1989, and the first version was released in 1991.
He continued to work on the language throughout the 1990s and until the early 2000s, when
he stepped down as the "Benevolent Dictator for Life" (BDFL) of the Python community.
He is also known for his contributions to the open-source community.
• Python, which is named after the Monty Python comedy group, is widely used in many
fields such as web development, scientific computing, data analysis, artificial intelligence
and more.
• It is known for its simplicity, readability and easy to learn. Python is also often used as a
first-language to teach programming.
STANDARD PYTHON ROAD MAP
• Basic Syntax
• Variables
• Data types (Strings, Numbers, List, Tuples, Sets, Bool)
• Control Flow (Conditions, Loops)
• Functions (Generators, iterators built-in, lambda)
• OOP (Classes, Objects, Inheritance, Abstraction)
• Decorators
• Exceptions
• Testing
• Modules
APPLICATIONS OF PYTHON
• Web development: Python has a number of popular web frameworks such as Flask and Django that make it
easy to build web applications. It can also be used to write scripts to automate web scraping and data
extraction.
• Scientific computing and data analysis: Python has a number of powerful libraries for data analysis and
visualization, such as NumPy, pandas, and Matplotlib. These libraries make it easy to work with large sets of
data and perform complex calculations.
• Machine learning and artificial intelligence: Python has become a popular choice for developing machine
learning and AI models, thanks to libraries such as scikit-learn, TensorFlow, and Keras.
• Automation and scripting: Python is often used for automating repetitive tasks and writing scripts to
automate workflows. It can be used to control and automate software, such as Blender, GIMP, and Autodesk
Maya, and even hardware like Raspberry Pi, Arduino.
• Game development: Python is also used to develop games using libraries like Pygame and PyOpenGL.
• Networking: Python has a number of libraries for working with network protocols, such as Scapy and
Twisted.
DOWNLOADING PYTHON
• Open a browser to the Python website and download the Windows installer.
• https://www.python.org/
• DOWNLOAD THE LATEST OR THE LONG TERM SUPPORT (LTS) VERSION
INSTALLING PYTHON
• Double click on the downloaded file and install Python for all users, and ensure that Python
is added to your path. Click on Install now to begin. Adding Python to the path will enable
us to use the Python interpreter from any part of the filesystem.
• DON’T MIND THE VERSION. ALWAYS GET THE LATEST OR THE LTS.
ADDING PYTHON TO PATH
• After the installation is complete, click Disable path length limit and then Close. Disabling
the path length limit means we can use more than 260 characters in a file path.
FINISHING
• Click Close to end the installation.
CODE EDITORS
• PyCharm
• VSCode
• Sublime Text
• Notepad++
PYTHON VIRTUAL ENVIRONMENT
• A virtual environment, or virtualenv, is a tool used to isolate specific Python environments on a single
machine, allowing for separate dependencies, packages, and Python versions for different projects.

• When you create a virtualenv, it creates a separate copy of Python and any packages you install in that
environment. This allows you to work on multiple projects on the same machine without them
interfering with each other. For example, you might have one project that requires Python 3.6 and
another that requires Python 3.8, or one project that uses a specific version of a package while another
project uses a different version. Virtual environments make it easy to switch between these different
environments without having to constantly re-install packages or change your global Python version.

• Additionally, using virtual environment can also make it easier to share your code with others, as you
can specify the exact versions of the packages your code depends on in a virtual environment. This
helps to avoid any compatibility issues with different versions of packages.
CREATING A PYTHON VIRTUAL
ENV
• To create a virtual environment in Windows using Python 3, you can use the built-in venv module. Here are the
steps:

• Open the command prompt or PowerShell.


• Navigate to the directory where you want to create the virtual environment.
• Run the command python -m venv env to create a virtual environment named "env". You can replace "env" with
the name of your choice.
• Activate the virtual environment by running the command env\Scripts\activate. The command prompt should
now be prefixed with the name of the virtual environment.
• You can now install packages and use them in this virtual environment without affecting other Python
installations or environments on your system.
• To deactivate the virtual environment, you can use the command deactivate.
• You can also use other tools like virtualenv or pipenv to create virtual environments in windows.
VARIABLES
Used to store values in a program. In Python, you can
use any name as a variable name, but it should not
start with a number or special characters. For
example:
x=5
y = "Hello, World!"
DATA TYPES
• Python supports various data types such as integers, floating-point numbers, strings, and
Boolean values. For example:
x = 5 # integer
y = 3.14 # float
z = "Hello, World!" # string
b = True # Boolean
OPERATORS
• Python supports various operators such as arithmetic, comparison, and logical operators. For example:
x=5
y=3

# Arithmetic operators
print(x + y) # 8
print(x - y) # 2
print(x * y) # 15
print(x / y) # 1.6666666

# Comparison operators
print(x == y) # False
print(x > y) # True

# Logical operators
print(x > 3 and x < 10) # True
CONDITIONAL STATEMENTS
• Used to control the flow of a program based on certain conditions. Python supports if, elif,
and else statements. For example:
x=5
if x > 0:
print("x is positive")
elif x < 0:
print("x is negative")
else:
print("x is zero")
LOOPS
• Used to execute a block of code multiple times. Python supports for and while loops. For example:
# For loop
for i in range(5):
print(i)

# while loop
i=0
while i < 5:
print(i)
i += 1
FUNCTIONS
• Used to group a set of related code together and can be reused throughout the program.
Python supports the use of functions with the 'def' keyword. For example:
def add(x, y):
return x + y

print(add(5, 3)) # 8
LISTS AND TUPLES
• These are both built-in data types that allow you to store multiple values in a single variable. Lists are enclosed in
square brackets [] and are mutable, meaning you can add, remove or change values within the list. Tuples are enclosed
in parentheses () and are immutable, meaning you can't change the values once they are assigned. For example:
# Lists
fruits = ["apple", "banana", "orange"]
print(fruits) # ["apple", "banana", "orange"]
fruits.append("mango")
print(fruits) # ["apple", "banana", "orange", "mango"]

# Tuples
numbers = (1, 2, 3)
print(numbers) # (1, 2, 3)
# numbers[1] = 4 # This will raise a TypeError, because tuples are immutable
DICTIONARIES
• Like lists and tuples, but instead of using indexing to access the values, you use keys.
Dictionaries are enclosed in curly braces {} and keys are unique within the dictionary. For
example:
person = {"name": "John", "age": 30, "gender": "male"}
print(person["name"]) # "John"
print(person["age"]) # 30
person["age"] = 31
print(person["age"]) # 31
MODULES AND LIBRARIES
• Python has many built-in modules and libraries that provide additional functionality. For
example, the math module provides mathematical functions, while the `os` module provides
functions for interacting with the operating system. You can also install third-party libraries
using package managers like pip. For example:
import math
print(math.pi) # 3.141592653589793

import os
print(os.getcwd()) # prints the current working directory
EXCEPTION HANDLING
• Exception handling is a way to handle errors that occur during the execution of a program.
Python uses try-except blocks to handle exceptions. For example:
try:
x=5/0
except ZeroDivisionError:
print("Cannot divide by zero.")
OBJECT-ORIENTED
PROGRAMMING (OOP)
• Python supports OOP, which is a programming paradigm that focuses on creating objects,
which have methods and properties, and are instances of classes. This allows for code reuse
and organization. For example:
DECORATORS
• Decorators are a way to add functionality to existing functions without modifying the
original code. They are defined using the @ symbol followed by the name of the function
that will be used as a decorator. They can be used to add logging, timing, or other types of
functionality to functions. For example:
CONTEXT MANAGERS
• An object that defines the methods __enter__() and __exit__() that are used to set up and
tear down resources.
• The most common use of context managers is to handle file I/O. For example:
with open("example.txt", "w") as file:
file.write("Hello World!")
CLOSING
• These are some of the fundamentals of Python
programming. Of course, there are more advanced
features and libraries available in Python, but
understanding these basics will provide a solid
foundation for further learning.

You might also like