SlideShare a Scribd company logo
1 of 42
CSE 120 - Python Programming
Course Handled By:
G.Gandhi Jaba Kumar,
Lecturer,
SRET.
1
INTRODUCTION
๏‚ง Python is a popular programming language. It was created by Guido van
Rossum, and released in 1991.
It is used for:
๏‚ง web development (server-side),
๏‚ง software development,
๏‚ง mathematics,
๏‚ง system scripting.
๏ƒ˜ It uses English keywords frequently where as other languages use
punctuation, and it has fewer syntactical constructions than other
languages.
2
๏ƒ˜ Python is Interpreted โˆ’ Python is processed at runtime by the interpreter. You
do not need to compile your program before executing it. This is similar to
PERL and PHP.
๏ƒ˜ Python is a Beginner's Language โˆ’ Python is a great language for the
beginner-level programmers and supports the development of a wide range
of applications from simple text processing to WWW browsers to games.
๏ƒ˜ Python is Interactive โˆ’ You can actually sit at a Python prompt and interact
with the interpreter directly to write your programs.
๏ƒ˜ Python is Object-Oriented โˆ’ Python supports Object-Oriented style or
technique of programming that encapsulates code within objects.
3
What can Python do?
๏ต Python can be used on a server to create web applications.
๏ต Python can be used alongside software to create workflows.
๏ต Python can connect to database systems. It can also read and modify files.
๏ต Python can be used to handle big data and perform complex mathematics.
๏ต Python can be used for rapid prototyping, or for production-ready software
development.
4
5
Why Python?
๏ต Python works on different platforms (Windows, Mac, Linux, Raspberry Pi,
etc).
๏ต Python has a simple syntax similar to the English language.
๏ต Python has syntax that allows developers to write programs with fewer
lines than some other programming languages.
๏ต Python runs on an interpreter system, meaning that code can be executed
as soon as it is written. This means that prototyping can be very quick.
๏ต Python can be treated in a procedural way, an object-oriented way or a
functional way.
6
Python Syntax
๏ต Syntax is one of the basic requirements that we must know to code in any
language.
๏ต In Python, we use indentation to represent the block of the code. We have
to follow some rules about how to use the indentation.
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.
๏ƒ˜ Python will give you an error if you skip the indentation.
๏ƒ˜ The number of spaces is up to you as a programmer, the most common use
is four, but it has to be at least one.
๏ƒ˜ You have to use the same number of spaces in the same block of code,
otherwise Python will give you an error
7
8
Python Comments
๏ต Comments can be used to explain Python code.
๏ต Comments can be used to make the code more readable.
๏ต Comments can be used to prevent execution when testing code.
Creating a Comment
๏ƒ˜ Comments starts with a #, and Python will ignore them:
Example
#This is a comment
print("Hello, World!")
9
10
Keywords
๏ต Python Keywords are special reserved words that convey a special meaning to the
compiler/interpreter. Each keyword has a special meaning and a specific operation.
These keywords can't be used as a variable.
๏ต Following is the List of Python Keywords.
True False None and as
asset def class continue break
else finally elif del except
global for if from import
raise try or return pass
nonlocal in not is lambda
11
12
Python Variables
๏ต Variables are nothing but reserved memory locations to store values. This
means that when you create a variable you reserve some space in memory.
๏ต Based on the data type of a variable, the interpreter allocates memory and
decides what can be stored in the reserved memory. Therefore, by
assigning different data types to variables, you can store integers, decimals
or characters in these variables.
Assigning Values to Variables
๏ต Python variables do not need explicit declaration to reserve memory space.
The declaration happens automatically when you assign a value to a
variable. The equal sign (=) is used to assign values to variables.
13
๏ƒ˜ The operand to the left of the = operator is the name of the variable and the
๏ƒ˜ operand to the right of the = operator is the value stored in the variable.
For example โˆ’
14
๏ƒ˜ Python allows you to assign a single value to several variables simultaneously.
For example โˆ’
a = b = c = 1
๏ƒ˜ Here, an integer object is created with the value 1, and all three variables are
assigned to the same memory location.
๏ƒ˜ You can also assign multiple objects to multiple variables.
For example โˆ’
a,b,c = 1,2,"john"
๏ƒ˜ Here, two integer objects with values 1 and 2 are assigned to variables a and b
respectively, and one string object with the value "john" is assigned to the
variable c.
Multiple Assignment
15
16
Re-declare a Variable
๏ต You can re-declare Python variables even after you have declared once.
๏ต Here we have Python declare variable initialized to f=0.
๏ต Later, we re-assign the variable f to value โ€œguru99โ€
17
Python Data Types
๏ƒ˜ Variables can hold values, and every value has a data-type.
๏ƒ˜ Python is a dynamically typed language; hence we do not need to define the
type of the variable while declaring it.
๏ƒ˜ The interpreter implicitly binds the value with its type.
a = 5
๏ƒ˜ The variable a holds integer value five and we did not define its type.
๏ƒ˜ Python interpreter will automatically interpret variables a as an integer type.
๏ƒ˜ Python enables us to check the type of the variable used in the program.
๏ƒ˜ Python provides us the type() function, which returns the type of the variable
passed.
18
19
Standard data types
๏ƒ˜ A variable can hold different types of values. For example, a person's name
must be stored as a string whereas its id must be stored as an integer.
๏ƒ˜ Python provides various standard data types that define the storage method
on each of them. The data types defined in Python are given below.
๏ƒ˜ Numbers
๏ƒ˜ Sequence Type
๏ƒ˜ Boolean
๏ƒ˜ Set
๏ƒ˜ Dictionary
20
Numbers
๏ต Number stores numeric values. The integer, float, and complex values belong to a
Python Numbers data-type.
๏ต Int - Integer value can be any length such as integers 10, 2, 29, -20, -150 etc.
Python has no restriction on the length of an integer. Its value belongs to int
๏ต Float - Float is used to store floating-point numbers like 1.9, 9.902, 15.2, etc. It is
accurate upto 15 decimal points.
๏ต complex - A complex number contains an ordered pair, i.e., x + iy where x and y
denote the real and imaginary parts, respectively. The complex numbers like 2.14j,
2.0 + 2.3j, etc.
21
For example;
22
Sequence Type
๏ต The string can be defined as the sequence of characters represented in the quotation
marks. In Python, we can use single, double, or triple quotes to define a string.
๏ต In the case of string handling, the operator + is used to concatenate two strings as
the operation "hello"+" python" returns "hello python".
๏ต The operator * is known as a repetition operator as the operation "Python" *2
returns 'Python Python'.
Example - 1
23
Example - 2
24
List
๏ต Python Lists are similar to arrays in C. However, the list can contain data
of different types. The items stored in the list are separated with a comma
(,) and enclosed within square brackets [].
๏ต We can use slice [:] operators to access the data of the list. The
concatenation operator (+) and repetition operator (*) works with the list in
the same way as they were working with the strings.
25
Consider the following example.
26
๏ƒ˜ A tuple is similar to the list in many ways. Like lists, tuples also contain the
collection of the items of different data types.
๏ƒ˜ The items of the tuple are separated with a comma (,) and enclosed in parentheses ().
๏ƒ˜ A tuple is a read-only data structure as we can't modify the size and value of the
items of a tuple.
Tuple
27
28
๏ƒ˜ Dictionary is an unordered set of a key-value pair of items. It is like an associative
array or a hash table where each key stores a specific value.
๏ƒ˜ Key can hold any primitive data type, whereas value is an arbitrary Python object.
๏ƒ˜ The items in the dictionary are separated with the comma (,) and enclosed in the
curly braces {}.
Consider the following example.
Dictionary
29
๏ƒ˜ Boolean type provides two built-in values, True and False. These values are used to
determine the given statement true or false.
๏ƒ˜ It denotes by the class bool. True can be represented by any non-zero value or 'T'
whereas false can be represented by the 0 or 'F'. Consider the following example.
# Python program to check the Boolean type
Boolean
30
Set
๏ƒ˜ Python Set is the unordered collection of the data type.
๏ƒ˜ It is iterable, mutable(can modify after creation), and has unique elements. In set, the
order of the elements is undefined;
๏ƒ˜ it may return the changed sequence of the element.
๏ƒ˜ The set is created by using a built-in function set(), or a sequence of elements is
passed in the curly braces and separated by the comma.
๏ƒ˜ It can contain various types of values.
31
32
Set
Consider the following example.
Python Operators
๏ƒ˜ The operator can be defined as a symbol which is responsible for a particular
operation between two operands.
๏ƒ˜ Operators are the pillars of a program on which the logic is built in a specific
programming language.
๏ƒ˜ Python provides a variety of operators, which are described as follows.
33
Arithmetic Operators
๏ต Arithmetic operators are used to perform arithmetic operations between two
operands. It includes + (addition), - (subtraction), *(multiplication), /(divide),
%(reminder), //(floor division), and exponent (**) operators.
Operator Description
+ (Addition) It is used to add two operands. For example, if a = 20, b =
10 => a+b = 30
- (Subtraction) It is used to subtract the second operand from the first
operand. If the first operand is less than the second operand,
the value results negative. For example, if a = 20, b = 10 =>
a - b = 10
/ (divide) It returns the quotient after dividing the first operand by the
second operand. For example, if a = 20, b = 10 => a/b = 2.0
* (Multiplication) It is used to multiply one operand with the other. For
example, if a = 20, b = 10 => a * b = 200
% (reminder) It returns the reminder after dividing the first operand by the
second operand. For example, if a = 20, b = 10 => a%b = 0
** (Exponent) It is an exponent operator represented as it calculates the
first operand power to the second operand.
// (Floor division) It gives the floor value of the quotient produced by dividing
the two operands.
34
Comparison operator
๏ต Comparison operators are used to comparing the value of the two operands and
returns
๏ต Boolean true or false accordingly. The comparison operators are described in the
following table.
Operator Description
== If the value of two operands is equal, then the condition
becomes true.
!= If the value of two operands is not equal, then the condition
becomes true.
<= If the first operand is less than or equal to the second
operand, then the condition becomes true.
>= If the first operand is greater than or equal to the second
operand, then the condition becomes true.
> If the first operand is greater than the second operand, then
the condition becomes true.
< If the first operand is less than the second operand, then the
condition becomes true.
35
Assignment Operators
๏ต The assignment operators are used to assign the value of the right expression to the
left operand. The assignment operators are described in the following table.
Operator Description
= It assigns the value of the right expression to the left operand.
+= It increases the value of the left operand by the value of the right operand and
assigns the modified value back to left operand. For example, if a = 10, b = 20
=> a+ = b will be equal to a = a+ b and therefore, a = 30.
-= It decreases the value of the left operand by the value of the right operand and
assigns the modified value back to left operand. For example, if a = 20, b = 10
=> a- = b will be equal to a = a- b and therefore, a = 10.
*= It multiplies the value of the left operand by the value of the right operand and
assigns the modified value back to then the left operand. For example, if a = 10,
b = 20 => a* = b will be equal to a = a* b and therefore, a = 200.
%= It divides the value of the left operand by the value of the right operand and
assigns the reminder back to the left operand. For example, if a = 20, b = 10 =>
a % = b will be equal to a = a % b and therefore, a = 0.
**= a**=b will be equal to a=a**b, for example, if a = 4, b =2, a**=b will assign
4**2 = 16 to a.
//= A//=b will be equal to a = a// b, for example, if a = 4, b = 3, a//=b will assign
4//3 = 1 to a. 36
Bitwise Operators
๏ต In Python, bitwise operators are used to performing bitwise calculations on
integers. The integers are first converted into binary and then operations are
performed on bit by bit, hence the name bitwise operators. Then the result is
returned in decimal format.
Operator Description
& (binary and) If both the bits at the same place in two operands are 1, then 1 is
copied to the result. Otherwise, 0 is copied.
| (binary or) The resulting bit will be 0 if both the bits are zero; otherwise, the
resulting bit will be 1.
^ (binary xor) The resulting bit will be 1 if both the bits are different; otherwise,
the resulting bit will be 0.
~ (negation) It calculates the negation of each bit of the operand, i.e., if the bit
is 0, the resulting bit will be 1 and vice versa.
<< (left shift) The left operand value is moved left by the number of bits present
in the right operand.
>> (right shift) The left operand is moved right by the number of bits present in
the right operand.
37
Logical Operators
๏ต The logical operators are used primarily in the expression evaluation to make a
decision. Python supports the following logical operators.
Operator Description
and If both the expression are true, then the condition will be
true. If a and b are the two expressions, a โ†’ true, b โ†’
true => a and b โ†’ true.
or If one of the expressions is true, then the condition will be
true. If a and b are the two expressions, a โ†’ true, b โ†’
false => a or b โ†’ true.
not If an expression a is true, then not (a) will be false and
vice versa.
38
Membership Operators
๏ต Python membership operators are used to check the membership of value inside a
Python data structure. If the value is present in the data structure, then the resulting
value is true otherwise it returns false.
Operator Description
in It is evaluated to be true if the first operand is found in the second
operand (list, tuple, or dictionary).
not in It is evaluated to be true if the first operand is not found in the second
operand (list, tuple, or dictionary).
39
Identity Operators
๏ต The identity operators are used to decide whether an element certain class or type.
Operator Description
is It is evaluated to be true if the reference present at both
sides point to the same object.
is not It is evaluated to be true if the reference present at both
sides do not point to the same object.
40
Operator Precedence
๏ต The precedence of the operators is essential to find out since it enables us to know which
operator should be evaluated first. The precedence table of the operators in Python is
given below.
41
42

More Related Content

Similar to Python - Module 1.ppt

Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| FundamentalsMohd Sajjad
ย 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answerskavinilavuG
ย 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answersRojaPriya
ย 
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdfCSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdfAbdulmalikAhmadLawan2
ย 
Python Interview Questions For Freshers
Python Interview Questions For FreshersPython Interview Questions For Freshers
Python Interview Questions For Fresherszynofustechnology
ย 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptxrohithprabhas1
ย 
Unit -1 CAP.pptx
Unit -1 CAP.pptxUnit -1 CAP.pptx
Unit -1 CAP.pptxmalekaanjum1
ย 
Python Programming-1.pptx of python by computer
Python Programming-1.pptx of python by computerPython Programming-1.pptx of python by computer
Python Programming-1.pptx of python by computersharanyarashmir5
ย 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming LanguageMansiSuthar3
ย 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming LanguageTahani Al-Manie
ย 
Python Programming 1.pptx
Python Programming 1.pptxPython Programming 1.pptx
Python Programming 1.pptxFrancis Densil Raj
ย 
Unit 2 python
Unit 2 pythonUnit 2 python
Unit 2 pythonpraveena p
ย 
Python Data Types
Python Data TypesPython Data Types
Python Data Typesathithanvijay
ย 
Top Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdfTop Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdfDatacademy.ai
ย 
Python ppt_118.pptx
Python ppt_118.pptxPython ppt_118.pptx
Python ppt_118.pptxMadhuriAnaparthy
ย 

Similar to Python - Module 1.ppt (20)

Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
ย 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
ย 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
ย 
Python by Rj
Python by RjPython by Rj
Python by Rj
ย 
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdfCSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
CSC2308 - PRINCIPLE OF PROGRAMMING II.pdf
ย 
GE3151_PSPP_UNIT_2_Notes
GE3151_PSPP_UNIT_2_NotesGE3151_PSPP_UNIT_2_Notes
GE3151_PSPP_UNIT_2_Notes
ย 
PYTHON.pdf
PYTHON.pdfPYTHON.pdf
PYTHON.pdf
ย 
Python Interview Questions For Freshers
Python Interview Questions For FreshersPython Interview Questions For Freshers
Python Interview Questions For Freshers
ย 
Python unit1
Python unit1Python unit1
Python unit1
ย 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptx
ย 
Unit -1 CAP.pptx
Unit -1 CAP.pptxUnit -1 CAP.pptx
Unit -1 CAP.pptx
ย 
Python Programming-1.pptx of python by computer
Python Programming-1.pptx of python by computerPython Programming-1.pptx of python by computer
Python Programming-1.pptx of python by computer
ย 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming Language
ย 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
ย 
Python Programming 1.pptx
Python Programming 1.pptxPython Programming 1.pptx
Python Programming 1.pptx
ย 
Unit 2 python
Unit 2 pythonUnit 2 python
Unit 2 python
ย 
Python Data Types
Python Data TypesPython Data Types
Python Data Types
ย 
Top Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdfTop Most Python Interview Questions.pdf
Top Most Python Interview Questions.pdf
ย 
Python programming
Python programmingPython programming
Python programming
ย 
Python ppt_118.pptx
Python ppt_118.pptxPython ppt_118.pptx
Python ppt_118.pptx
ย 

More from jaba kumar

Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.pptjaba kumar
ย 
blood donation camp.ppt
blood donation camp.pptblood donation camp.ppt
blood donation camp.pptjaba kumar
ย 
SQL Data types and Constarints.pptx
SQL Data types and Constarints.pptxSQL Data types and Constarints.pptx
SQL Data types and Constarints.pptxjaba kumar
ย 
2.Introduction to Network Devices.ppt
2.Introduction to Network Devices.ppt2.Introduction to Network Devices.ppt
2.Introduction to Network Devices.pptjaba kumar
ย 
NW_Tools.ppt
NW_Tools.pptNW_Tools.ppt
NW_Tools.pptjaba kumar
ย 
FDS-CS8393 BME MODEL QP2.doc
FDS-CS8393 BME MODEL QP2.docFDS-CS8393 BME MODEL QP2.doc
FDS-CS8393 BME MODEL QP2.docjaba kumar
ย 

More from jaba kumar (6)

Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.ppt
ย 
blood donation camp.ppt
blood donation camp.pptblood donation camp.ppt
blood donation camp.ppt
ย 
SQL Data types and Constarints.pptx
SQL Data types and Constarints.pptxSQL Data types and Constarints.pptx
SQL Data types and Constarints.pptx
ย 
2.Introduction to Network Devices.ppt
2.Introduction to Network Devices.ppt2.Introduction to Network Devices.ppt
2.Introduction to Network Devices.ppt
ย 
NW_Tools.ppt
NW_Tools.pptNW_Tools.ppt
NW_Tools.ppt
ย 
FDS-CS8393 BME MODEL QP2.doc
FDS-CS8393 BME MODEL QP2.docFDS-CS8393 BME MODEL QP2.doc
FDS-CS8393 BME MODEL QP2.doc
ย 

Recently uploaded

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
ย 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
ย 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
ย 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
ย 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
ย 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
ย 
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
ย 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
ย 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
ย 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
ย 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
ย 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
ย 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
ย 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
ย 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
ย 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
ย 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
ย 

Recently uploaded (20)

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
ย 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
ย 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ย 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
ย 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
ย 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
ย 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
ย 
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
ย 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
ย 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
ย 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
ย 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
ย 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
ย 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
ย 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
ย 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
ย 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
ย 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
ย 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
ย 

Python - Module 1.ppt

  • 1. CSE 120 - Python Programming Course Handled By: G.Gandhi Jaba Kumar, Lecturer, SRET. 1
  • 2. INTRODUCTION ๏‚ง Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. It is used for: ๏‚ง web development (server-side), ๏‚ง software development, ๏‚ง mathematics, ๏‚ง system scripting. ๏ƒ˜ It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages. 2
  • 3. ๏ƒ˜ Python is Interpreted โˆ’ Python is processed at runtime by the interpreter. You do not need to compile your program before executing it. This is similar to PERL and PHP. ๏ƒ˜ Python is a Beginner's Language โˆ’ Python is a great language for the beginner-level programmers and supports the development of a wide range of applications from simple text processing to WWW browsers to games. ๏ƒ˜ Python is Interactive โˆ’ You can actually sit at a Python prompt and interact with the interpreter directly to write your programs. ๏ƒ˜ Python is Object-Oriented โˆ’ Python supports Object-Oriented style or technique of programming that encapsulates code within objects. 3
  • 4. What can Python do? ๏ต Python can be used on a server to create web applications. ๏ต Python can be used alongside software to create workflows. ๏ต Python can connect to database systems. It can also read and modify files. ๏ต Python can be used to handle big data and perform complex mathematics. ๏ต Python can be used for rapid prototyping, or for production-ready software development. 4
  • 5. 5
  • 6. Why Python? ๏ต Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). ๏ต Python has a simple syntax similar to the English language. ๏ต Python has syntax that allows developers to write programs with fewer lines than some other programming languages. ๏ต Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick. ๏ต Python can be treated in a procedural way, an object-oriented way or a functional way. 6
  • 7. Python Syntax ๏ต Syntax is one of the basic requirements that we must know to code in any language. ๏ต In Python, we use indentation to represent the block of the code. We have to follow some rules about how to use the indentation. 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. ๏ƒ˜ Python will give you an error if you skip the indentation. ๏ƒ˜ The number of spaces is up to you as a programmer, the most common use is four, but it has to be at least one. ๏ƒ˜ You have to use the same number of spaces in the same block of code, otherwise Python will give you an error 7
  • 8. 8
  • 9. Python Comments ๏ต Comments can be used to explain Python code. ๏ต Comments can be used to make the code more readable. ๏ต Comments can be used to prevent execution when testing code. Creating a Comment ๏ƒ˜ Comments starts with a #, and Python will ignore them: Example #This is a comment print("Hello, World!") 9
  • 10. 10
  • 11. Keywords ๏ต Python Keywords are special reserved words that convey a special meaning to the compiler/interpreter. Each keyword has a special meaning and a specific operation. These keywords can't be used as a variable. ๏ต Following is the List of Python Keywords. True False None and as asset def class continue break else finally elif del except global for if from import raise try or return pass nonlocal in not is lambda 11
  • 12. 12
  • 13. Python Variables ๏ต Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. ๏ต Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals or characters in these variables. Assigning Values to Variables ๏ต Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables. 13
  • 14. ๏ƒ˜ The operand to the left of the = operator is the name of the variable and the ๏ƒ˜ operand to the right of the = operator is the value stored in the variable. For example โˆ’ 14
  • 15. ๏ƒ˜ Python allows you to assign a single value to several variables simultaneously. For example โˆ’ a = b = c = 1 ๏ƒ˜ Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. ๏ƒ˜ You can also assign multiple objects to multiple variables. For example โˆ’ a,b,c = 1,2,"john" ๏ƒ˜ Here, two integer objects with values 1 and 2 are assigned to variables a and b respectively, and one string object with the value "john" is assigned to the variable c. Multiple Assignment 15
  • 16. 16
  • 17. Re-declare a Variable ๏ต You can re-declare Python variables even after you have declared once. ๏ต Here we have Python declare variable initialized to f=0. ๏ต Later, we re-assign the variable f to value โ€œguru99โ€ 17
  • 18. Python Data Types ๏ƒ˜ Variables can hold values, and every value has a data-type. ๏ƒ˜ Python is a dynamically typed language; hence we do not need to define the type of the variable while declaring it. ๏ƒ˜ The interpreter implicitly binds the value with its type. a = 5 ๏ƒ˜ The variable a holds integer value five and we did not define its type. ๏ƒ˜ Python interpreter will automatically interpret variables a as an integer type. ๏ƒ˜ Python enables us to check the type of the variable used in the program. ๏ƒ˜ Python provides us the type() function, which returns the type of the variable passed. 18
  • 19. 19
  • 20. Standard data types ๏ƒ˜ A variable can hold different types of values. For example, a person's name must be stored as a string whereas its id must be stored as an integer. ๏ƒ˜ Python provides various standard data types that define the storage method on each of them. The data types defined in Python are given below. ๏ƒ˜ Numbers ๏ƒ˜ Sequence Type ๏ƒ˜ Boolean ๏ƒ˜ Set ๏ƒ˜ Dictionary 20
  • 21. Numbers ๏ต Number stores numeric values. The integer, float, and complex values belong to a Python Numbers data-type. ๏ต Int - Integer value can be any length such as integers 10, 2, 29, -20, -150 etc. Python has no restriction on the length of an integer. Its value belongs to int ๏ต Float - Float is used to store floating-point numbers like 1.9, 9.902, 15.2, etc. It is accurate upto 15 decimal points. ๏ต complex - A complex number contains an ordered pair, i.e., x + iy where x and y denote the real and imaginary parts, respectively. The complex numbers like 2.14j, 2.0 + 2.3j, etc. 21
  • 23. Sequence Type ๏ต The string can be defined as the sequence of characters represented in the quotation marks. In Python, we can use single, double, or triple quotes to define a string. ๏ต In the case of string handling, the operator + is used to concatenate two strings as the operation "hello"+" python" returns "hello python". ๏ต The operator * is known as a repetition operator as the operation "Python" *2 returns 'Python Python'. Example - 1 23
  • 25. List ๏ต Python Lists are similar to arrays in C. However, the list can contain data of different types. The items stored in the list are separated with a comma (,) and enclosed within square brackets []. ๏ต We can use slice [:] operators to access the data of the list. The concatenation operator (+) and repetition operator (*) works with the list in the same way as they were working with the strings. 25
  • 26. Consider the following example. 26
  • 27. ๏ƒ˜ A tuple is similar to the list in many ways. Like lists, tuples also contain the collection of the items of different data types. ๏ƒ˜ The items of the tuple are separated with a comma (,) and enclosed in parentheses (). ๏ƒ˜ A tuple is a read-only data structure as we can't modify the size and value of the items of a tuple. Tuple 27
  • 28. 28
  • 29. ๏ƒ˜ Dictionary is an unordered set of a key-value pair of items. It is like an associative array or a hash table where each key stores a specific value. ๏ƒ˜ Key can hold any primitive data type, whereas value is an arbitrary Python object. ๏ƒ˜ The items in the dictionary are separated with the comma (,) and enclosed in the curly braces {}. Consider the following example. Dictionary 29
  • 30. ๏ƒ˜ Boolean type provides two built-in values, True and False. These values are used to determine the given statement true or false. ๏ƒ˜ It denotes by the class bool. True can be represented by any non-zero value or 'T' whereas false can be represented by the 0 or 'F'. Consider the following example. # Python program to check the Boolean type Boolean 30
  • 31. Set ๏ƒ˜ Python Set is the unordered collection of the data type. ๏ƒ˜ It is iterable, mutable(can modify after creation), and has unique elements. In set, the order of the elements is undefined; ๏ƒ˜ it may return the changed sequence of the element. ๏ƒ˜ The set is created by using a built-in function set(), or a sequence of elements is passed in the curly braces and separated by the comma. ๏ƒ˜ It can contain various types of values. 31
  • 33. Python Operators ๏ƒ˜ The operator can be defined as a symbol which is responsible for a particular operation between two operands. ๏ƒ˜ Operators are the pillars of a program on which the logic is built in a specific programming language. ๏ƒ˜ Python provides a variety of operators, which are described as follows. 33
  • 34. Arithmetic Operators ๏ต Arithmetic operators are used to perform arithmetic operations between two operands. It includes + (addition), - (subtraction), *(multiplication), /(divide), %(reminder), //(floor division), and exponent (**) operators. Operator Description + (Addition) It is used to add two operands. For example, if a = 20, b = 10 => a+b = 30 - (Subtraction) It is used to subtract the second operand from the first operand. If the first operand is less than the second operand, the value results negative. For example, if a = 20, b = 10 => a - b = 10 / (divide) It returns the quotient after dividing the first operand by the second operand. For example, if a = 20, b = 10 => a/b = 2.0 * (Multiplication) It is used to multiply one operand with the other. For example, if a = 20, b = 10 => a * b = 200 % (reminder) It returns the reminder after dividing the first operand by the second operand. For example, if a = 20, b = 10 => a%b = 0 ** (Exponent) It is an exponent operator represented as it calculates the first operand power to the second operand. // (Floor division) It gives the floor value of the quotient produced by dividing the two operands. 34
  • 35. Comparison operator ๏ต Comparison operators are used to comparing the value of the two operands and returns ๏ต Boolean true or false accordingly. The comparison operators are described in the following table. Operator Description == If the value of two operands is equal, then the condition becomes true. != If the value of two operands is not equal, then the condition becomes true. <= If the first operand is less than or equal to the second operand, then the condition becomes true. >= If the first operand is greater than or equal to the second operand, then the condition becomes true. > If the first operand is greater than the second operand, then the condition becomes true. < If the first operand is less than the second operand, then the condition becomes true. 35
  • 36. Assignment Operators ๏ต The assignment operators are used to assign the value of the right expression to the left operand. The assignment operators are described in the following table. Operator Description = It assigns the value of the right expression to the left operand. += It increases the value of the left operand by the value of the right operand and assigns the modified value back to left operand. For example, if a = 10, b = 20 => a+ = b will be equal to a = a+ b and therefore, a = 30. -= It decreases the value of the left operand by the value of the right operand and assigns the modified value back to left operand. For example, if a = 20, b = 10 => a- = b will be equal to a = a- b and therefore, a = 10. *= It multiplies the value of the left operand by the value of the right operand and assigns the modified value back to then the left operand. For example, if a = 10, b = 20 => a* = b will be equal to a = a* b and therefore, a = 200. %= It divides the value of the left operand by the value of the right operand and assigns the reminder back to the left operand. For example, if a = 20, b = 10 => a % = b will be equal to a = a % b and therefore, a = 0. **= a**=b will be equal to a=a**b, for example, if a = 4, b =2, a**=b will assign 4**2 = 16 to a. //= A//=b will be equal to a = a// b, for example, if a = 4, b = 3, a//=b will assign 4//3 = 1 to a. 36
  • 37. Bitwise Operators ๏ต In Python, bitwise operators are used to performing bitwise calculations on integers. The integers are first converted into binary and then operations are performed on bit by bit, hence the name bitwise operators. Then the result is returned in decimal format. Operator Description & (binary and) If both the bits at the same place in two operands are 1, then 1 is copied to the result. Otherwise, 0 is copied. | (binary or) The resulting bit will be 0 if both the bits are zero; otherwise, the resulting bit will be 1. ^ (binary xor) The resulting bit will be 1 if both the bits are different; otherwise, the resulting bit will be 0. ~ (negation) It calculates the negation of each bit of the operand, i.e., if the bit is 0, the resulting bit will be 1 and vice versa. << (left shift) The left operand value is moved left by the number of bits present in the right operand. >> (right shift) The left operand is moved right by the number of bits present in the right operand. 37
  • 38. Logical Operators ๏ต The logical operators are used primarily in the expression evaluation to make a decision. Python supports the following logical operators. Operator Description and If both the expression are true, then the condition will be true. If a and b are the two expressions, a โ†’ true, b โ†’ true => a and b โ†’ true. or If one of the expressions is true, then the condition will be true. If a and b are the two expressions, a โ†’ true, b โ†’ false => a or b โ†’ true. not If an expression a is true, then not (a) will be false and vice versa. 38
  • 39. Membership Operators ๏ต Python membership operators are used to check the membership of value inside a Python data structure. If the value is present in the data structure, then the resulting value is true otherwise it returns false. Operator Description in It is evaluated to be true if the first operand is found in the second operand (list, tuple, or dictionary). not in It is evaluated to be true if the first operand is not found in the second operand (list, tuple, or dictionary). 39
  • 40. Identity Operators ๏ต The identity operators are used to decide whether an element certain class or type. Operator Description is It is evaluated to be true if the reference present at both sides point to the same object. is not It is evaluated to be true if the reference present at both sides do not point to the same object. 40
  • 41. Operator Precedence ๏ต The precedence of the operators is essential to find out since it enables us to know which operator should be evaluated first. The precedence table of the operators in Python is given below. 41
  • 42. 42