SlideShare ist ein Scribd-Unternehmen logo
1 von 35
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!

Weitere ähnliche Inhalte

Ähnlich wie PE1 Module 2.ppt

C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till nowAmAn Singh
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till nowAmAn Singh
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programmingsavitamhaske
 
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 laLEOFAKE
 
python operators.ppt
python operators.pptpython operators.ppt
python operators.pptErnieAcuna
 
Introduction to golang
Introduction to golangIntroduction to golang
Introduction to golangwww.ixxo.io
 
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 expressionFarshidKhan
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2dplunkett
 

Ähnlich wie PE1 Module 2.ppt (20)

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
 
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
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2
 
cprogrammingoperator.ppt
cprogrammingoperator.pptcprogrammingoperator.ppt
cprogrammingoperator.ppt
 

Mehr von balewayalew

Chapter 1-Introduction.ppt
Chapter 1-Introduction.pptChapter 1-Introduction.ppt
Chapter 1-Introduction.pptbalewayalew
 
Data Analytics.ppt
Data Analytics.pptData Analytics.ppt
Data Analytics.pptbalewayalew
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.pptbalewayalew
 
PE1 Module 3.ppt
PE1 Module 3.pptPE1 Module 3.ppt
PE1 Module 3.pptbalewayalew
 
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).pptxbalewayalew
 
Chapter -5- Augumented Reality (AR).pptx
Chapter -5- Augumented Reality (AR).pptxChapter -5- Augumented Reality (AR).pptx
Chapter -5- Augumented Reality (AR).pptxbalewayalew
 
PE1 Module 1.ppt
PE1 Module 1.pptPE1 Module 1.ppt
PE1 Module 1.pptbalewayalew
 
Ch 1-Non-functional Requirements.ppt
Ch 1-Non-functional Requirements.pptCh 1-Non-functional Requirements.ppt
Ch 1-Non-functional Requirements.pptbalewayalew
 
Ch 6 - Requirement Management.pptx
Ch 6 - Requirement Management.pptxCh 6 - Requirement Management.pptx
Ch 6 - Requirement Management.pptxbalewayalew
 

Mehr von 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
 

Kürzlich hochgeladen

multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communicationpanditadesh123
 
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptJohnWilliam111370
 
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSHigh Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSsandhya757531
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdfsahilsajad201
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Coursebim.edu.pl
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Erbil Polytechnic University
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESkarthi keyan
 
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdfDEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdfAkritiPradhan2
 
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书rnrncn29
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosVictor Morales
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewsandhya757531
 
Secure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech LabsSecure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech Labsamber724300
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfBalamuruganV28
 
A brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProA brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProRay Yuan Liu
 
Curve setting (Basic Mine Surveying)_MI10412MI.pptx
Curve setting (Basic Mine Surveying)_MI10412MI.pptxCurve setting (Basic Mine Surveying)_MI10412MI.pptx
Curve setting (Basic Mine Surveying)_MI10412MI.pptxRomil Mishra
 
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfComprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfalene1
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsResearcher Researcher
 
Theory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdfTheory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdfShreyas Pandit
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Sumanth A
 

Kürzlich hochgeladen (20)

multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communication
 
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
 
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSHigh Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdf
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Course
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
 
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdfDEVICE DRIVERS AND INTERRUPTS  SERVICE MECHANISM.pdf
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
 
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
 
KCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitosKCD Costa Rica 2024 - Nephio para parvulitos
KCD Costa Rica 2024 - Nephio para parvulitos
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overview
 
Secure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech LabsSecure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech Labs
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdf
 
A brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision ProA brief look at visionOS - How to develop app on Apple's Vision Pro
A brief look at visionOS - How to develop app on Apple's Vision Pro
 
Curve setting (Basic Mine Surveying)_MI10412MI.pptx
Curve setting (Basic Mine Surveying)_MI10412MI.pptxCurve setting (Basic Mine Surveying)_MI10412MI.pptx
Curve setting (Basic Mine Surveying)_MI10412MI.pptx
 
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdfComprehensive energy systems.pdf Comprehensive energy systems.pdf
Comprehensive energy systems.pdf Comprehensive energy systems.pdf
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending Actuators
 
Theory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdfTheory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdf
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
 

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