0% found this document useful (0 votes)
13 views72 pages

Python 1

This document provides an introduction to Python programming including what Python is, why it is popular, its applications, and basic Python concepts. Python was created in 1989 by Guido Van Rossum and is an interpreted, high-level programming language with an easy syntax. It supports object-oriented programming and has many libraries, making it popular for web development, machine learning, data science, and more. The document covers Python syntax, variables, data types, operators, conditional statements, loops, functions, and other core concepts.

Uploaded by

ASHIEK. A
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
13 views72 pages

Python 1

This document provides an introduction to Python programming including what Python is, why it is popular, its applications, and basic Python concepts. Python was created in 1989 by Guido Van Rossum and is an interpreted, high-level programming language with an easy syntax. It supports object-oriented programming and has many libraries, making it popular for web development, machine learning, data science, and more. The document covers Python syntax, variables, data types, operators, conditional statements, loops, functions, and other core concepts.

Uploaded by

ASHIEK. A
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 72

Introduction to

Python Programming
What we give you?

 What is python programming?


 Why python is more popular?
 Why do people use python?
 Applications and Uses of Python
 Basic python programming
What is Python Programmig?

 Python was created by Guido Van Rossum in


1989
 Python is a general purpose high level
interpreted language with easy syntax
 It is more interactive and supports Object
Oriented programming
Why python is more
popular?

Easy Syntax

Open Source Python Applications

More libraries
Why do people use
python?

 Python is object-oriented Structure supports


such concepts as polymorphism, operation
overloading, and multiple inheritance.
 It's free (open source) Downloading and
installing Python is free and easy
Why do people use
python?

 It is more powerful,
Dynamic typing
Library utilities
 Platform Independent
Applications of Python
 Web Development
 Game Development
 Machine Learning and Artificial Intelligence
 Data Science and Data Visualization
 Desktop GUI
 Web Scraping Applications
 Business Applications
 Audio and Video Applications
Python Syntax
Python Indentation
 Indentation refers to the spaces at the
beginning of a code line.
 Where in other programming languages the
indentation in code is for readability only, the
indentation in Python is very important.
 Python uses indentation to indicate a block of
code.
Example 1
Example 2
Python Variable
 It is used to store data or values
 In python, do not need to be
declared with any particular type
 String variables can be declared
either by using single or double
quotes
Rules for Python variables

 A variable name must start with a letter or the


underscore character
 A variable name cannot start with a number
 A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
 Variable names are case-sensitive (age, Age and
AGE are three different variables)
Example 1
Example 2
Data Types

 It is used to store data with different types


 Python having built-in data types by
default:
 Text Type : str
 Numeric Types : int, float, complex
 Sequence Types : list, tuple, range
 Boolean Type: bool
Getting Data Type using type() function
Basic Concept in String
Inbuilt Functions in python
Getting input From User
Python Operators
 An operator is the symbol that specifies an operation to
be performed on the operands
Example : a + b, + is the operator.
Unary Operator
 Need only one operand
Example: -a, ~b
Binary Operator
 Acts upon two operands
Example: a - b
Types of Operators
 Arithmetic Operator
 Comparison Operator
 Assignment Operator
 Logical Operator
 Bitwise Operator
 Membership Operator
 Identity Operator
Arithmetic Operator
Comparison Operator
Bitwise Operator

 It works on bits and perform bit by bit operation


Example: a = 60 (0011 1100)
b = 13 (0000 1101)
A B A&B A|B A^B ~A

0 0 0 0 0 1

0 1 0 1 1 1

1 0 0 1 1 0

1 1 1 1 0 0
Queries

a = 60
b = 13
1. What will be the Output of a & b?
2. What will be the Output of a | b?
3. What will be the Output of a ^ b?
4. What will be the Output of ~a?
5. What will be the Output of a<<1 and a<<2?
6. What will be the Output of a>>1 and a>>2?
Bitwise Operator
Membership Operator

 Used to test for membership in a sequence


such as strings, lists or tuples
Keyword: in, not in
Operator Example Description
in X in Y Result is True if X is a
member of Y

not in X not in Y Result is True if X is


not a member of Y
Identity Operator

 Used to compare the memory locations of two


objects
Keyword: is, is not
Operator Example Description
is X is Y Result is True if id(X)
and id(Y) same

is not X is not Y Result is True if id(X)


is not equal to id(Y)
Example
Programs

 Write a program to do arithmetic operations


 Write a program to swap two variables
 Write a program to swap two variables without
using third variable
Python Collections

 List is a collection which is ordered and


changeable.
 Allows duplicate members.
 Lists are represented with square brackets
 Collection of different data types
Example
 A tuple is a collection which is ordered
and unchangeable.
 In Python tuples are written with round
brackets.
 Collection of different data types
 Allows duplicate members.
Quries
Let us assign tuple, a =(1, 2, 3, 4, “Python”)
What will be the output for following code?
1. a[1] = 10
print(a)
2. a. append(20)
print(a)
 A set is a collection which is unordered and
unindexed.
 In Python sets are written with curly brackets.
 Collection of different data types
 Doesn’t allow duplicate values
 Once set is created can not be change only we
can add data
Example
Dictionary
 A dictionary is a
collection which is
unordered,
changeable and
indexed.
 In Python
dictionaries are
written with curly
What is If Statement?

 If Statement is used for decision making.


 It will run the body of code only when IF statement is
true, else it will run ELSE part.
Syntax
if expression:
statement
else:
statement
How to check more than two
condition?

 elif is the keyword which is used to check multiple


conditions in python
Syntax
if expression:
statement
elif expression:
statement
else:
statement
Example Programs
 Write a program to Find greatest of three number
 Write a program to check whether the given number is odd
or even
 Write a program to check if the person is eligible to vote
 Write a program to check whether the given number is
positive or negative or zero
 Write a program to find given year is leap year or not
While Loop
 While loop we can execute a set of statements as long as a condition
is true.

Syntax

while expression:

statement

Example

i=1

while i < 5:

print(‘Python Programming’)

i +=1
Example

 Write a program to find sum of n number


 Write a program to find whether the given
number is palindrome number or not
 Write a program to reverse a given number
 Write a program to find whether the given
number is Armstrong number or not
 Write a program to Print the Fibonacci sequence
Python For Loop
 A for loop is used for iterating over a sequence
(that is either a list, a tuple, a dictionary, a set,
or a string).
Syntax
for variable name in range():
statement
Example
 Write a program to display multiplication table
 Write a program to find factorial of a number
 Write a program to find whether the given number is prime or not
 Write a program to find prime number in a given interval
 Find Odd or even number between intervals
 Adding 2 array values
 Write a program to count number of odd number and even
number from input data and it should contain minimum 10
numbers and it must be string data
Example
 Count vowels and consonants in string
 Count small and capital letters in string
 Interchanging first and last elements in list
 Count occurrence of data in list
 Sum of N number in a list
 Armstrong number between intervals
 Largest element in a list
 Smallest element in a list
Example
 Copy array data from one array to another
 Display duplicate data in list
 Reverse data in a list
 Display data in even position
 Display data in odd position
 String Palindrome
 Remove Punctuation
 Display array value in Ascending order
 Display array value in Descending order
Example
 Display grade based on average mark
 Print all numbers in a range divisible by a given
number
 Possible combination for 3 integer input
 Display total number of digits from input
 Display smallest divisor of an integer
 Print all integers that aren’t divisible by given divisor
Example
 Print Identity matrix
 Check input is perfect number or not
 Check input is Strong number or not
 Check given strings are anagram or not
 Find largest string from input
 Count and display even numbers in a list
 Remove duplicate element from list
 Print the incremented date
Example
 LCM of Two number
 GCD of two number
 Replace character with new character
 Amicable number or not
 Python Program to Form an Integer that has the Number of
Digits at Ten’s Place and Digit of the Entered Integer at
One’s Place
 Frequency of each letter
 Find Sub string present or not
Example
 Python Program to Add a Key-Value Pair to the Dictionary
 Python Program to Concatenate Two Dictionaries Into One
 Python Program to Check if a Given Key Exists in a
Dictionary or Not
 Python Program to Generate a Dictionary that Contains
Numbers (between 1 and n) in the form of x:x*x
 Python Program to Sum All the Items in a Dictionary
 Python Program to Multiply All the Items in a Dictionary
Function
 A function is a block of code which only runs
when it is called.
 You can pass data, known as parameters, into
a function.
 A function can return data as a result.
Example
def my_function():
  print("Hello Everyone")

my_function()
Example
 Addition using function
 Calculator using functions
 Odd or Even using recursion
 Fibonacci using function
 Factorial Using Function
 LCM of two number using recursion
 GCD of 2 numbers using recursion
 Prime or not using recursion
Lambda Function
 A lambda function is a small anonymous
function.
 A lambda function can take any number of
arguments, but can only have one expression.
Syntax
lambda arguments : expression
Map Function
 Map is the inbuilt function
 It is used to apply a function to all the
elements of sequence.
Syntax
map(function, iterable(s))
Filter Function
 Filter is the inbuilt function
 It is used to filter the elements of iterables
based on some function (ie., It filter out the
unwanted data).
Syntax
filter(function, iterable(s))
Reduce Function
 Reduce is the inbuilt function
 reduce() works differently
than map() and filter(). It does not return a new
list based on the function and iterable we've
passed. Instead, it returns a single value.
Syntax
reduce(function, iterable(s))
Oops Concept in Python

 An object-oriented programming is to design


the program using classes and objects.
 The object is related to real-word entities such
as book, house, pencil, etc.
 The oops concept focuses on writing the
reusable code. 
Major principles of object-
oriented programming
system,
 Class
 Object
 Method
 Inheritance
 Polymorphism
 Data Abstraction
 Encapsulation
Class
 The class can be defined as a collection of
objects. It is a logical entity that has some
specific attributes and methods. 
Object
 The object is an entity that has state and behavior.
 It may be any real-world object like the mouse, keyboard,
chair, table, pen, etc.
 Everything in Python is an object, and almost everything
has attributes and methods.
 When we define a class, it needs to create an object to
allocate the memory
Polymorphism
 Polymorphism contains two words "poly" and
"morphs".
 By polymorphism, we understand that one
task can be performed in different ways.
Encapsulation
 Encapsulation is also an essential aspect of
object-oriented programming.
 In encapsulation, code and data are wrapped
together within a single unit.
Inheritance
 Inheritance is the most important aspect of object-oriented
programming, It specifies that the child object acquires all the properties
and behaviors of the parent object.
 By using inheritance, we can create a class which uses all the properties
and behavior of another class.
 The new class is known as a derived class or child class, and the one
whose properties are acquired is known as a base class or parent class.
 It provides the re-usability of the code.
Types of Inheritance

 Single Level Inheritance – It will have only one


base class and one derived class.
Syntax

class Base1:  

    <class-suite>  

class Derived(Base1):  

    <class-suite> 
 Multi-Level Inheritance – It will have one base
class and more than one derived class.
Syntax

class class1:  

    <class-suite>  

class class2(class1):  

    <class-suite> 

class class3(class2):  

    <class-suite> 

.
 Multiple Inheritance – It will have more than
one parent class and only one derived class
Syntax

class Base1:  

    <class-suite>  

class Base2:  

    <class-suite>  

.  

.  

class BaseN:  

    <class-suite>  

class Derived(Base1, Base2, ...... BaseN):  

    <class-suite> 
THANK YOU

You might also like