SlideShare a Scribd company logo
PE1 Module 2
Python Fundamentals
2
Introduction
 Python consists of a number of coding basics.
 What do you understand from the below code?
It may look like a foreign language.
 To make meaningful sentences in a foreign language, you must
learn its alphabet, words, and grammar.
 The same is true for a programming language. Python is a
programming language.
 To write meaningful programs, you must learn the programming
language’s semantic, syntax rules and basic elements.
 The syntax rules determine which instructions are legal.
 The semantic rules determine the meaning of the instructions.
 Basic elements are the building blocks to write the instructions.
3
Python Program Basics
 Basic elements/fundamentals to create a python
program:
Variables
Identifiers
Keywords
Datatypes
Input/Output
Comments
Constants
Operators
4
Variables
 Variables are containers for storing data values.
5
Identifiers
 An identifier is a name given to a variable.
 Python has some rules about how identifiers can be formed
Every identifier must begin with a letter or
underscore, which may be followed by any sequence
of letters, digits, or underscores.
first
conversion
payRate
counter1
Legal
employee salary
hello!
one+two
#second
Illegal: Explain why they are illegal?
6
Identifiers
 Identifiers are case-sensitive
>>> x = 10
>>> X = 5.7
>>> print(x)
10
>>> print(X)
5.7
7
Keywords
 Some identifiers are part of Python itself (they are called
reserved words or keywords) and cannot be used by
programmers as ordinary identifiers
False class finally is return
None continue for lambda try
True def from nonlocal while
and del global not with
as elif if or yield
assert else import pass
break except in raise
Python Keywords
8
Datatypes
 A data type represents the type of data stored into a variable
or memory.
 Python assumes the type of a variable based on the assigned
value.
9
Two types of Datatypes
1. Built- in data types: The datatypes which are
already available in Python language: =>our focus
2. User-defined data types: The datatypes which
are created by programmers.
10
Major built- in data types:
 int datatype: represents an integer number. An integer
number is a number with out any decimal point. Example
a=10 or b=-20
 float datatype: represents floating point numbers. A
floating number is a number that contains a decimal point.
Example a=123.45 or b=-20.25
 bool datatype: represents Boolean value. A Boolean value
is a value that can be either True or False.
 str datatype: represents string. A string is a
sequence/group of characters. String can be enclosed
inside:
Single quotes: 'Welcome to Python Programming'
Double quotes: "Welcome to Python Programming"
11
 As a matter of fact, we can do various kinds of conversions
between strings, integers and floats using the built-in int,
float, and str types.
Datatype Conversion
>>> x =
10
>>>
float(x)
10.0
>>>
str(x)
'10'
>>>
>>> y =
"20"
>>>
float(y)
20.0
>>>
int(y)
20
>>>
>>> z =
30.0
>>>
int(z)
30
>>>
str(z)
'30.0'
>>>
integer  float
integer  string
string  float
string  integer
float  integer
float  string
12
Datatype Conversion
13
Input/Output in Python
 You can display program data to the console in
Python with print().
 The input() function pauses program execution to
allow the user to type in a line of input from the
keyboard.
 Python takes all the input as a string input by
default.
14
Output in Python
15
Input in Python
16
Input/Output
17
Input/Output
18
Python Comments
 Comments are descriptions that help programmers
better understand the intent and functionality of the
program.
Using comments in programs makes our code more
understandable.
Comments can also be used to ignore some code while
testing other blocks of code.
 Comments are completely ignored by the Python
interpreter.
 Comments can be:
Single-Line Comments
Multi-Line Comment
19
Single-Line Comments in Python
 In Python, we use the hash symbol # to write a single-line
comment.
20
Multi-Line Comments in Python
 We can use # at the beginning of each line of comment on
multiple lines.
 We can use enclosed triple double quotes.
 We can use enclosed triple single quotes.
21
Constants
 A constant is a type of variable whose value cannot be changed.
 It is helpful to think of constants as containers that hold
information which cannot be changed later.
 Python doesn’t have built-in constant types.
 By convention, Python uses a variable whose name contains all
capital letters to define a constant.
22
Operators in Python
 Operators are special symbols used for specific purposes.
 Python provides many operators for manipulating data.
 Operators perform an action on one or more operands.
Arithmetical Operators
Assignment Operators
Relational Operators
Logical operators
Increment and Decrement Operators
Bitwise Operators
Membership Operators
23
Python Arithmetic Operators
OperatorDescription Example
+ Addition - Adds values on either side of the
operator
10 + 20 will give 30
- Subtraction - Subtracts right hand operand
from left hand operand
10 - 20 will give -10
* Multiplication - Multiplies values on either
side of the operator
10 * 20 will give 200
/ Division - Divides left hand operand by right
hand operand
20 / 10 will give 2
% Modulus - Divides left hand operand by right
hand operand and returns remainder
20% 10 will give 0
** Exponent - Performs exponential (power)
calculation on operators
10**20 will give 10 to
the power 20
// Floor Division - The division of operands
where the result is the quotient in which the
digits after the decimal point are removed.
9//2 is equal to 4 and
9.0//2.0 is equal to 4.0
24
Python Assignment Operators
Operator Description Example
= Simple assignment operator, Assigns values from right side
operands to left side operand
c = a + b will assign the
value of a + b to c
+= Add AND assignment operator, It adds right operand to the left
operand and assign the result to left operand
c += a is equivalent to
c = c + a
-= Subtract AND assignment operator, It subtracts right operand from
the left operand and assign the result to left operand
c -= a is equivalent to
c = c - a
*= Multiply AND assignment operator, It multiplies right operand with
the left operand and assign the result to left operand
c *= a is equivalent to
c = c * a
/= Divide AND assignment operator, It divides left operand with the
right operand and assign the result to left operand
c /= a is equivalent to
c = c / a
%= Modulus AND assignment operator, It takes modulus using two
operands and assign the result to left operand
c %= a is equivalent to
c = c % a
**= Exponent AND assignment operator, Performs exponential (power)
calculation on operators and assign value to the left operand
c **= a is equivalent to
c = c ** a
//= Floor Division and assigns a value, Performs floor division on
operators and assign value to the left operand
c //= a is equivalent to
c = c // a
25
Python Relational Operators
Operator Description Example
== Checks if the value of two operands are equal or not, if yes
then condition becomes true.
(10 == 20) is not true.
!= Checks if the value of two operands are equal or not, if
values are not equal then condition becomes true.
(10!= 20) is true.
<> Checks if the value of two operands are equal or not, if
values are not equal then condition becomes true.
(10 <> 20) is true. This is
similar to != operator.
> Checks if the value of left operand is greater than the value
of right operand, if yes then condition becomes true.
(10 > 20) is not true.
< Checks if the value of left operand is less than the value of
right operand, if yes then condition becomes true.
(10 < 20) is true.
>= Checks if the value of left operand is greater than or equal
to the value of right operand, if yes then condition becomes
true.
(10>= 20) is not true.
<= Checks if the value of left operand is less than or equal to
the value of right operand, if yes then condition becomes
true.
(a10<= 20) is true.
26
Python Logical Operators
Operator Description Example
and Called Logical AND operator. If both the
operands are true then then condition
becomes true.
(10 and 20) is true.
or Called Logical OR Operator. If any of the two
operands are non zero then then condition
becomes true.
(10 or 0) is true.
not Called Logical NOT Operator. Use to
reverses the logical state of its operand. If a
condition is true then Logical NOT operator
will make false.
not(10 and 20) is false.
27
Increment and Decrement Operators
 The increment operator ++
It adds one to a variable.
 The decrement operator --
It subtracts one from a variable
 Increment and decrement operators can be used
before(prefix) or after(postfix) a variable.
 In prefix mode (++ variable or - -variable) the operator
increments or decrements, then returns the value of the
variable.
 In postfix mode (variable++ or variable- -) the operator
returns the current value of the variable, then increments or
decrements.
28
Post increment Operator
 The position of the ++ determines when the value
is incremented. If the ++ is after the variable, then
the incrementing is done last (a post
increment).
 count = 3
 amount = 2 * count++
 amount gets the value of 2 * 3, which is 6, and then
1 gets added to count.
 So, after executing the last line, amount is 6 and
count is 4.
29
Pre increment Operator
 If the ++ is before the variable, then the
incrementing is done first (a pre increment).
 count = 3
 amount = 2 * ++count
 1 gets added to count first, then amount gets the
value of 2 * 4, which is 8.
 So, after executing the last line, amount is 8 and
count is 4.
30
Post decrement Operator
 The position of the -- determines when the value is
decremented. If the -- is after the variable, then
the decrementing is done last (a post
decrement).
 count = 3
 amount = 2 * count--
 amount gets the value of 2 * 3, which is 6, and
then 1 gets subtracted from count.
 So, after executing the last line, amount is 6 and
count is 2.
31
Pre decrement Operator
 If the -- is before the variable, then the
decrementing is done first (a pre decrement).
 count = 3
 amount = 2 * --count
 1 gets subtracted from count first, then amount
gets the value of 2 * 2, which is 4.
 So, after executing the last line, amount is 4 and
count is 2.
32
Python Bitwise Operators
Operator Description Example
& Binary AND Operator copies a bit 1 to the
result if it exists in both operands.
(60& 13) will give 12 which
is 0000 1100
| Binary OR Operator copies a bit 1 if it exists in
either operand.
(60 | 13) will give 61 which
is 0011 1101
^ Binary XOR Operator sets the bit to 1 if the bit
of the operand opposite.
(60^ 13) will give 49 which
is 0011 0001
~ Binary Ones Complement Operator is unary
and has the effect of 'flipping' bits.
(~60 ) will give -60 which
is 1100 0011
<< Binary Left Shift Operator. The left operands
value is moved left by the number of bits
specified by the right operand.
60<< 2 will give 240 which
is 1111 0000
>> Binary Right Shift Operator. The left operands
value is moved right by the number of bits
specified by the right operand.
60>> 2 will give 15 which
is 0000 1111
33
Python Membership Operators
In addition to the operators discussed previously, Python has
membership operators, which test for membership in a sequence,
such as strings, lists, or tuples.
Operator Description Example
in Evaluates to true if it finds a variable in the
specified sequence and false otherwise.
x in y, here in results in a 1 if
x is a member of sequence y.
not in Evaluates to true if it does not finds a variable
in the specified sequence and false otherwise.
x not in y, here not in
results in a 1 if x is a member
of sequence y.
34
Python Operators Precedence
Operator Description
() ++ - - ** Parentheses, increment, decrement, exponentiation
~ complement
* / % // Multiply, divide, modulo and floor division
+ - Addition and subtraction
>> << Right and left bitwise shift
& Bitwise 'AND'
^ | Bitwise exclusive `OR' and regular `OR'
<= < > >= Comparison operators
<> == != Equality operators
= %= /= //= -= += *=
**=
Assignment operators
is is not Identity operators
in not in Membership operators
not or and Logical operators
35
Any Question?
Thank You!

More Related Content

Similar to PE1 Module 2.ppt

Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
Asheesh kushwaha
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 
C program
C programC program
C program
AJAL A J
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
savitamhaske
 
Operators
OperatorsOperators
Operators
VijayaLakshmi506
 
Operators in Python Arithmetic Operators
Operators in Python Arithmetic OperatorsOperators in Python Arithmetic Operators
Operators in Python Arithmetic Operators
ramireddyobulakondar
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
Thesis Scientist Private Limited
 
data type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de ladata type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de la
LEOFAKE
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
malekaanjum1
 
C language
C languageC language
C language
Mohamed Bedair
 
C PRESENTATION.pptx
C PRESENTATION.pptxC PRESENTATION.pptx
C PRESENTATION.pptx
VAIBHAV175947
 
python operators.ppt
python operators.pptpython operators.ppt
python operators.ppt
ErnieAcuna
 
C++ chapter 2
C++ chapter 2C++ chapter 2
C++ chapter 2
SHRIRANG PINJARKAR
 
Introduction to golang
Introduction to golangIntroduction to golang
Introduction to golang
www.ixxo.io
 
Basic commands in C++
Basic commands in C++Basic commands in C++
Basic commands in C++
Mujeeb UR Rahman
 
C operator and expression
C operator and expressionC operator and expression
C operator and expression
LavanyaManokaran
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
Cse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expressionCse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expression
FarshidKhan
 

Similar to PE1 Module 2.ppt (20)

Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
C program
C programC program
C program
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Operators
OperatorsOperators
Operators
 
Operators in Python Arithmetic Operators
Operators in Python Arithmetic OperatorsOperators in Python Arithmetic Operators
Operators in Python Arithmetic Operators
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
data type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de ladata type.pptxddddswwyertr hai na ki extend kr de la
data type.pptxddddswwyertr hai na ki extend kr de la
 
Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
 
C language
C languageC language
C language
 
C PRESENTATION.pptx
C PRESENTATION.pptxC PRESENTATION.pptx
C PRESENTATION.pptx
 
python operators.ppt
python operators.pptpython operators.ppt
python operators.ppt
 
C++ chapter 2
C++ chapter 2C++ chapter 2
C++ chapter 2
 
Introduction to golang
Introduction to golangIntroduction to golang
Introduction to golang
 
Basic commands in C++
Basic commands in C++Basic commands in C++
Basic commands in C++
 
C operator and expression
C operator and expressionC operator and expression
C operator and expression
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
 
Cse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expressionCse lecture-4.1-c operators and expression
Cse lecture-4.1-c operators and expression
 

More from balewayalew

slides.06.pptx
slides.06.pptxslides.06.pptx
slides.06.pptx
balewayalew
 
slides.07.pptx
slides.07.pptxslides.07.pptx
slides.07.pptx
balewayalew
 
slides.08.pptx
slides.08.pptxslides.08.pptx
slides.08.pptx
balewayalew
 
Chapter 1-Introduction.ppt
Chapter 1-Introduction.pptChapter 1-Introduction.ppt
Chapter 1-Introduction.ppt
balewayalew
 
Data Analytics.ppt
Data Analytics.pptData Analytics.ppt
Data Analytics.ppt
balewayalew
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.ppt
balewayalew
 
PE1 Module 3.ppt
PE1 Module 3.pptPE1 Module 3.ppt
PE1 Module 3.ppt
balewayalew
 
Chapter -6- Ethics and Professionalism of ET (2).pptx
Chapter -6- Ethics and Professionalism of ET (2).pptxChapter -6- Ethics and Professionalism of ET (2).pptx
Chapter -6- Ethics and Professionalism of ET (2).pptx
balewayalew
 
Chapter -5- Augumented Reality (AR).pptx
Chapter -5- Augumented Reality (AR).pptxChapter -5- Augumented Reality (AR).pptx
Chapter -5- Augumented Reality (AR).pptx
balewayalew
 
Chapter 8.ppt
Chapter 8.pptChapter 8.ppt
Chapter 8.ppt
balewayalew
 
PE1 Module 1.ppt
PE1 Module 1.pptPE1 Module 1.ppt
PE1 Module 1.ppt
balewayalew
 
chapter7.ppt
chapter7.pptchapter7.ppt
chapter7.ppt
balewayalew
 
chapter6.ppt
chapter6.pptchapter6.ppt
chapter6.ppt
balewayalew
 
chapter5.ppt
chapter5.pptchapter5.ppt
chapter5.ppt
balewayalew
 
chapter4.ppt
chapter4.pptchapter4.ppt
chapter4.ppt
balewayalew
 
chapter3.ppt
chapter3.pptchapter3.ppt
chapter3.ppt
balewayalew
 
chapter2.ppt
chapter2.pptchapter2.ppt
chapter2.ppt
balewayalew
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
balewayalew
 
Ch 1-Non-functional Requirements.ppt
Ch 1-Non-functional Requirements.pptCh 1-Non-functional Requirements.ppt
Ch 1-Non-functional Requirements.ppt
balewayalew
 
Ch 6 - Requirement Management.pptx
Ch 6 - Requirement Management.pptxCh 6 - Requirement Management.pptx
Ch 6 - Requirement Management.pptx
balewayalew
 

More from balewayalew (20)

slides.06.pptx
slides.06.pptxslides.06.pptx
slides.06.pptx
 
slides.07.pptx
slides.07.pptxslides.07.pptx
slides.07.pptx
 
slides.08.pptx
slides.08.pptxslides.08.pptx
slides.08.pptx
 
Chapter 1-Introduction.ppt
Chapter 1-Introduction.pptChapter 1-Introduction.ppt
Chapter 1-Introduction.ppt
 
Data Analytics.ppt
Data Analytics.pptData Analytics.ppt
Data Analytics.ppt
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.ppt
 
PE1 Module 3.ppt
PE1 Module 3.pptPE1 Module 3.ppt
PE1 Module 3.ppt
 
Chapter -6- Ethics and Professionalism of ET (2).pptx
Chapter -6- Ethics and Professionalism of ET (2).pptxChapter -6- Ethics and Professionalism of ET (2).pptx
Chapter -6- Ethics and Professionalism of ET (2).pptx
 
Chapter -5- Augumented Reality (AR).pptx
Chapter -5- Augumented Reality (AR).pptxChapter -5- Augumented Reality (AR).pptx
Chapter -5- Augumented Reality (AR).pptx
 
Chapter 8.ppt
Chapter 8.pptChapter 8.ppt
Chapter 8.ppt
 
PE1 Module 1.ppt
PE1 Module 1.pptPE1 Module 1.ppt
PE1 Module 1.ppt
 
chapter7.ppt
chapter7.pptchapter7.ppt
chapter7.ppt
 
chapter6.ppt
chapter6.pptchapter6.ppt
chapter6.ppt
 
chapter5.ppt
chapter5.pptchapter5.ppt
chapter5.ppt
 
chapter4.ppt
chapter4.pptchapter4.ppt
chapter4.ppt
 
chapter3.ppt
chapter3.pptchapter3.ppt
chapter3.ppt
 
chapter2.ppt
chapter2.pptchapter2.ppt
chapter2.ppt
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
 
Ch 1-Non-functional Requirements.ppt
Ch 1-Non-functional Requirements.pptCh 1-Non-functional Requirements.ppt
Ch 1-Non-functional Requirements.ppt
 
Ch 6 - Requirement Management.pptx
Ch 6 - Requirement Management.pptxCh 6 - Requirement Management.pptx
Ch 6 - Requirement Management.pptx
 

Recently uploaded

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 

Recently uploaded (20)

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 

PE1 Module 2.ppt

  • 1. PE1 Module 2 Python Fundamentals
  • 2. 2 Introduction  Python consists of a number of coding basics.  What do you understand from the below code? It may look like a foreign language.  To make meaningful sentences in a foreign language, you must learn its alphabet, words, and grammar.  The same is true for a programming language. Python is a programming language.  To write meaningful programs, you must learn the programming language’s semantic, syntax rules and basic elements.  The syntax rules determine which instructions are legal.  The semantic rules determine the meaning of the instructions.  Basic elements are the building blocks to write the instructions.
  • 3. 3 Python Program Basics  Basic elements/fundamentals to create a python program: Variables Identifiers Keywords Datatypes Input/Output Comments Constants Operators
  • 4. 4 Variables  Variables are containers for storing data values.
  • 5. 5 Identifiers  An identifier is a name given to a variable.  Python has some rules about how identifiers can be formed Every identifier must begin with a letter or underscore, which may be followed by any sequence of letters, digits, or underscores. first conversion payRate counter1 Legal employee salary hello! one+two #second Illegal: Explain why they are illegal?
  • 6. 6 Identifiers  Identifiers are case-sensitive >>> x = 10 >>> X = 5.7 >>> print(x) 10 >>> print(X) 5.7
  • 7. 7 Keywords  Some identifiers are part of Python itself (they are called reserved words or keywords) and cannot be used by programmers as ordinary identifiers False class finally is return None continue for lambda try True def from nonlocal while and del global not with as elif if or yield assert else import pass break except in raise Python Keywords
  • 8. 8 Datatypes  A data type represents the type of data stored into a variable or memory.  Python assumes the type of a variable based on the assigned value.
  • 9. 9 Two types of Datatypes 1. Built- in data types: The datatypes which are already available in Python language: =>our focus 2. User-defined data types: The datatypes which are created by programmers.
  • 10. 10 Major built- in data types:  int datatype: represents an integer number. An integer number is a number with out any decimal point. Example a=10 or b=-20  float datatype: represents floating point numbers. A floating number is a number that contains a decimal point. Example a=123.45 or b=-20.25  bool datatype: represents Boolean value. A Boolean value is a value that can be either True or False.  str datatype: represents string. A string is a sequence/group of characters. String can be enclosed inside: Single quotes: 'Welcome to Python Programming' Double quotes: "Welcome to Python Programming"
  • 11. 11  As a matter of fact, we can do various kinds of conversions between strings, integers and floats using the built-in int, float, and str types. Datatype Conversion >>> x = 10 >>> float(x) 10.0 >>> str(x) '10' >>> >>> y = "20" >>> float(y) 20.0 >>> int(y) 20 >>> >>> z = 30.0 >>> int(z) 30 >>> str(z) '30.0' >>> integer  float integer  string string  float string  integer float  integer float  string
  • 13. 13 Input/Output in Python  You can display program data to the console in Python with print().  The input() function pauses program execution to allow the user to type in a line of input from the keyboard.  Python takes all the input as a string input by default.
  • 18. 18 Python Comments  Comments are descriptions that help programmers better understand the intent and functionality of the program. Using comments in programs makes our code more understandable. Comments can also be used to ignore some code while testing other blocks of code.  Comments are completely ignored by the Python interpreter.  Comments can be: Single-Line Comments Multi-Line Comment
  • 19. 19 Single-Line Comments in Python  In Python, we use the hash symbol # to write a single-line comment.
  • 20. 20 Multi-Line Comments in Python  We can use # at the beginning of each line of comment on multiple lines.  We can use enclosed triple double quotes.  We can use enclosed triple single quotes.
  • 21. 21 Constants  A constant is a type of variable whose value cannot be changed.  It is helpful to think of constants as containers that hold information which cannot be changed later.  Python doesn’t have built-in constant types.  By convention, Python uses a variable whose name contains all capital letters to define a constant.
  • 22. 22 Operators in Python  Operators are special symbols used for specific purposes.  Python provides many operators for manipulating data.  Operators perform an action on one or more operands. Arithmetical Operators Assignment Operators Relational Operators Logical operators Increment and Decrement Operators Bitwise Operators Membership Operators
  • 23. 23 Python Arithmetic Operators OperatorDescription Example + Addition - Adds values on either side of the operator 10 + 20 will give 30 - Subtraction - Subtracts right hand operand from left hand operand 10 - 20 will give -10 * Multiplication - Multiplies values on either side of the operator 10 * 20 will give 200 / Division - Divides left hand operand by right hand operand 20 / 10 will give 2 % Modulus - Divides left hand operand by right hand operand and returns remainder 20% 10 will give 0 ** Exponent - Performs exponential (power) calculation on operators 10**20 will give 10 to the power 20 // Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. 9//2 is equal to 4 and 9.0//2.0 is equal to 4.0
  • 24. 24 Python Assignment Operators Operator Description Example = Simple assignment operator, Assigns values from right side operands to left side operand c = a + b will assign the value of a + b to c += Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand c += a is equivalent to c = c + a -= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand c -= a is equivalent to c = c - a *= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand c *= a is equivalent to c = c * a /= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand c /= a is equivalent to c = c / a %= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand c %= a is equivalent to c = c % a **= Exponent AND assignment operator, Performs exponential (power) calculation on operators and assign value to the left operand c **= a is equivalent to c = c ** a //= Floor Division and assigns a value, Performs floor division on operators and assign value to the left operand c //= a is equivalent to c = c // a
  • 25. 25 Python Relational Operators Operator Description Example == Checks if the value of two operands are equal or not, if yes then condition becomes true. (10 == 20) is not true. != Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (10!= 20) is true. <> Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. (10 <> 20) is true. This is similar to != operator. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (10 > 20) is not true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (10 < 20) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (10>= 20) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (a10<= 20) is true.
  • 26. 26 Python Logical Operators Operator Description Example and Called Logical AND operator. If both the operands are true then then condition becomes true. (10 and 20) is true. or Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. (10 or 0) is true. not Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. not(10 and 20) is false.
  • 27. 27 Increment and Decrement Operators  The increment operator ++ It adds one to a variable.  The decrement operator -- It subtracts one from a variable  Increment and decrement operators can be used before(prefix) or after(postfix) a variable.  In prefix mode (++ variable or - -variable) the operator increments or decrements, then returns the value of the variable.  In postfix mode (variable++ or variable- -) the operator returns the current value of the variable, then increments or decrements.
  • 28. 28 Post increment Operator  The position of the ++ determines when the value is incremented. If the ++ is after the variable, then the incrementing is done last (a post increment).  count = 3  amount = 2 * count++  amount gets the value of 2 * 3, which is 6, and then 1 gets added to count.  So, after executing the last line, amount is 6 and count is 4.
  • 29. 29 Pre increment Operator  If the ++ is before the variable, then the incrementing is done first (a pre increment).  count = 3  amount = 2 * ++count  1 gets added to count first, then amount gets the value of 2 * 4, which is 8.  So, after executing the last line, amount is 8 and count is 4.
  • 30. 30 Post decrement Operator  The position of the -- determines when the value is decremented. If the -- is after the variable, then the decrementing is done last (a post decrement).  count = 3  amount = 2 * count--  amount gets the value of 2 * 3, which is 6, and then 1 gets subtracted from count.  So, after executing the last line, amount is 6 and count is 2.
  • 31. 31 Pre decrement Operator  If the -- is before the variable, then the decrementing is done first (a pre decrement).  count = 3  amount = 2 * --count  1 gets subtracted from count first, then amount gets the value of 2 * 2, which is 4.  So, after executing the last line, amount is 4 and count is 2.
  • 32. 32 Python Bitwise Operators Operator Description Example & Binary AND Operator copies a bit 1 to the result if it exists in both operands. (60& 13) will give 12 which is 0000 1100 | Binary OR Operator copies a bit 1 if it exists in either operand. (60 | 13) will give 61 which is 0011 1101 ^ Binary XOR Operator sets the bit to 1 if the bit of the operand opposite. (60^ 13) will give 49 which is 0011 0001 ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~60 ) will give -60 which is 1100 0011 << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. 60<< 2 will give 240 which is 1111 0000 >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. 60>> 2 will give 15 which is 0000 1111
  • 33. 33 Python Membership Operators In addition to the operators discussed previously, Python has membership operators, which test for membership in a sequence, such as strings, lists, or tuples. Operator Description Example in Evaluates to true if it finds a variable in the specified sequence and false otherwise. x in y, here in results in a 1 if x is a member of sequence y. not in Evaluates to true if it does not finds a variable in the specified sequence and false otherwise. x not in y, here not in results in a 1 if x is a member of sequence y.
  • 34. 34 Python Operators Precedence Operator Description () ++ - - ** Parentheses, increment, decrement, exponentiation ~ complement * / % // Multiply, divide, modulo and floor division + - Addition and subtraction >> << Right and left bitwise shift & Bitwise 'AND' ^ | Bitwise exclusive `OR' and regular `OR' <= < > >= Comparison operators <> == != Equality operators = %= /= //= -= += *= **= Assignment operators is is not Identity operators in not in Membership operators not or and Logical operators