Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
175 views

Python Programming ppt0

This document provides an introduction to Python programming. It discusses what programming is, what Python is, Python's features and uses. It then covers basic Python concepts like variables, data types, operators, functions, conditionals and loops. The document contains examples of basic Python code like print statements, comments, arithmetic operations and exercises for readers to practice. It aims to teach Python programming from the ground up in a progressive manner.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
175 views

Python Programming ppt0

This document provides an introduction to Python programming. It discusses what programming is, what Python is, Python's features and uses. It then covers basic Python concepts like variables, data types, operators, functions, conditionals and loops. The document contains examples of basic Python code like print statements, comments, arithmetic operations and exercises for readers to practice. It aims to teach Python programming from the ground up in a progressive manner.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Python Programming

Beginner to Advanced Level


What is Programming

 Programming is a way for us to tell computers what to do. Computer is a very dumb
machine and it only does what we tell it to do. Hence we learn programming and tell
computers to do what we are very slow at - computation. If I ask you to calculate 5+6,
you will immediately say 11. How about 23453453 X 56456?
 You will start searching for a calculator or jump to a new tab to calculate the same. This
will help you learn python from starting to the end. We will start from 0 and by the time
we end this course, I promise you will be a Job ready Python developer!
What is Python?

• Python is a dynamically typed, general purpose programming language that supports an


object-oriented programming approach as well as a functional programming approach.
• Python is an interpreted and a high-level programming language.
• It was created by Guido Van Rossum in 1989.
Features Of Python

• Python is simple and easy to understand.


• It is Interpreted and platform-independent which makes debugging very easy.
• Python is an open-source programming language.
• Python provides very big library support. Some of the popular libraries include NumPy,
Tensorflow, Selenium, OpenCV, etc.
• It is possible to integrate other programming languages within python.
What is Python used for

• Python is used in Data Visualization to create plots and graphical representations.


• Python helps in Data Analytics to analyze and understand raw data for insights and
trends.
• It is used in AI and Machine Learning to simulate human behavior and to learn from
past data without hard coding.
• It is used to create web applications.
• It can be used to handle databases.
• It is used in business and accounting to perform complex mathematical operations
along with quantitative and qualitative analysis.
Print

 print("Hello World")
 print(5)

 Hello World
 5
Why I love python (And you will too...)

  Let me start with a story! Back in my college, I used to learn C and C++ programming
in depth, used to score good marks. I created a bunch of printing, conditionals and loop
program. Now what? I wanted to benefit from the same In my second year of college, I
started working (I mean actually working in the industry) with the python programming
language. I was not so good with it but I used to write code for a client and actually
make good money without having to actually master Python. Then I got curious and
started working on his Python skills even more. I then got into web scraping and trust
me I made some good easy money on Fiverr just by writing some python programs and
charging on per webpagebasis to my clients ( I used to automate scraping).
 Long story short, Python made a huge impact in my career.
What can Python do for you?

 I want to show you some python programs I created which will surely inspire you to
create your own versions of the same as we progress through this tutorial. Do not try to
recreate them just yet if you are a beginner and just started working on Python. We will
make progress gradually trust me.
 Jarvis
 Love calculator
 Face recognition
 Flappy Bird game
 Snake game
Modules and pip in Python!

 Module is like a code library which can be used to borrow code written by somebody
else in our python program. There are two types of modules in python:
1. Built in Modules - These modules are ready to import and use and ships with the
python interpreter. there is no need to install such modules explicitly.
2. External Modules - These modules are imported from a third party file or can be
installed using a package manager like pip or conda. Since this code is written by
someone else, we can install different versions of a same module with time.
Using a module in Python

 It can be used as a package manager pip to install a python module. Lets install a


module called pandas using the following command.
pip install pandas
 We use the import syntax to import a module in Python.
import pandas
# Read and work with a file named 'words.csv’
df = pandas.read_csv('words.csv’)
print(df) # This will display first few rows from the words.csv file
 Our First Program

 What does print in python means?


Print is a function.
 Now what is function?
Function is used to perform any task.
 And to invoke any function we use parenthesis() like this.
 Print(Hello World)
Error, Hello World is not a valid object.
 Print(“Hello world”)
Now Hello world is a string. Successful.
 print("---Your poem here---")
Comments in Python

 A comment is a part of the coding file that the programmer does not want to execute, rather the
programmer uses it to either explain a block of code or to avoid the execution of a specific part of code
while testing.
 To write a comment just add a ‘#’ at the start of the line.
 Single Line comment
#This is a 'Single-Line Comment'
 print("This is a print statement.")
This is a print statement.
 print("Hello World !!!") #Printing Hello World
Hello World !!!
 print("Python Program")#print("Python Program")
Python Program
 Multi-Line Comments:
To write multi-line comments you can use ‘#’ at each line or you can use the multiline string.
 #It will execute a block of code if a specified condition is true.
 #If the condition is false then it will execute another block of code.
p=7
if (p > 5):
print("p is greater than 5.")
else:
print("p is not greater than 5.")
p is greater than 5.
 """This is an if-else statement.
 It will execute a block of code if a specified condition is true.
 If the condition is false then it will execute another block of code."""
p=7
if (p > 5):
print("p is greater than 5.")
else:
print("p is not greater than 5.")
p is greater than 5.
Escape Sequence Characters

 To insert characters that cannot be directly used in a string, we use an escape sequence
character.
 An escape sequence character is a backslash \ followed by the character you want to
insert.
 An example of a character that cannot be directly used in a string is a double quote
inside a string that is surrounded by double quotes:
print("This doesnt "execute")
print("This will \" execute")
Print statement

 The syntax of a print statement looks something like this:


print(object(s), sep=separator, end=end, file=file, flush=flush)
1. object(s): Any object, and as many as you like. Will be converted to string
before printed
2. sep='separator': Specify how to separate the objects, if there is more than
one. Default is ' '
3. end='end': Specify what to print at the end. Default is '\n' (line feed)
4. file: An object with a write method. Default is sys.stdout
What is a variable?

 Variable is like a container that holds data. Very similar to how our containers in
kitchen holds sugar, salt etc Creating a variable is like creating a placeholder in
memory and assigning it some value. In Python its as easy as writing:
 a=1
 b = True
 c = "Harry"
 d = None
What is a Data Type?

 Data type specifies the type of value a variable holds. This is required in programming
to do various operations without causing an error.
In python, we can print the type of any operator using type function:
 a=1
 print(type(a))
 b = "1"
 print(type(b))
 Variables and Data Types

 1. Numeric data: int, float, complex


int: 3, -8, 0
float: 7.349, -9.0, 0.0000001
complex: 6 + 2i
 2. Text data: str
str: "Hello World!!!", "Python Programming”
 3. Boolean data:
Boolean data consists of values True or False.
 4. Sequenced data: list, tuple
 list: A list is an ordered collection of data with elements separated by a comma and enclosed within square brackets. Lists
are mutable and can be modified after creation.
 list1 = [8, 2.3, [-4, 5], ["apple", "banana"]]
print(list1)
 [8, 2.3, [-4, 5], ['apple', 'banana']]
 Tuple: A tuple is an ordered collection of data with elements separated by a comma and
enclosed within parentheses. Tuples are immutable and can not be modified after creation.
 tuple1 = (("parrot", "sparrow"), ("Lion", "Tiger"))
print(tuple1)
 (('parrot', 'sparrow'), ('Lion', 'Tiger’))
 5. Mapped data: dict
 dict: A dictionary is an unordered collection of data containing a key:value pair. The key:value
pairs are enclosed within curly brackets.
 dict1 = {"name":"Sakshi", "age":20, "canVote":True}
print(dict1)
 {'name': 'Sakshi', 'age': 20, 'canVote': True}
Operators

 Python has different types of operators for different operations. To create a calculator
we require arithmetic operators.
Operator Operator Name Example

+ Addition 15+7

- Subtraction 15-7

* Multiplication 5*7

** Exponential 5**3
/ Division 5/3
% Modulus 15%7

// Floor Division 15//7


Exercise 1

 n = 15
 m=7
 ans1 = n+m
 print("Addition of",n,"and",m,"is", ans1)
 ans2 = n-m
 print("Subtraction of",n,"and",m,"is", ans2)
 ans3 = n*m
 print("Multiplication of",n,"and",m,"is", ans3)
 ans4 = n/m
 print("Division of",n,"and",m,"is", ans4)
 ans5 = n%m
 print("Modulus of",n,"and",m,"is", ans5)
 ans6 = n//m
 print("Floor Division of",n,"and",m,"is", ans6)
LAB EXERCISE

 Create a calculator capable of performing addition, subtraction, multiplication and


division operations on two numbers. Your program should format the output in a
readable manner!
 Hint:
a = 50
b=3
print("The value of", a, "+", b, "is: ", a + b)
print("The value of", a, "-", b, "is: ", a - b)
print("The value of", a, "*", b, "is: ", a * b)
print("The value of", a, "/", b, "is: ", a / b)
Calculator()

 def calculator():  elif operator == '*':


 num1 = float(input("Enter first number: "))  result = num1 * num2
 num2 = float(input("Enter second number: "))  print("{} * {} = {}".format(num1, num2,
 operator = input("Enter operator (+, -, *, /): result))
")
 elif operator == '/':

 result = num1 / num2
 if operator == '+':
 print("{} / {} = {}".format(num1, num2,
 result = num1 + num2
result))
 print("{} + {} = {}".format(num1, num2,
result))  else:
 elif operator == '-':  print("Invalid operator! Please choose
 result = num1 - num2
from (+, -, *, /)")
 print("{} - {} = {}".format(num1, num2,
result))  calculator()
Thank you

You might also like