0% found this document useful (0 votes)
3 views11 pages

lecture 7 (1)

The document provides an overview of string quotations in Python, explaining the use of single, double, and triple quotes for string literals. It also covers tuple assignment, illustrating how multiple variables can be assigned values from a tuple in a single statement, and discusses various types of operators in Python including arithmetic and comparison operators, along with examples of their usage.

Uploaded by

vishal10thakwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

lecture 7 (1)

The document provides an overview of string quotations in Python, explaining the use of single, double, and triple quotes for string literals. It also covers tuple assignment, illustrating how multiple variables can be assigned values from a tuple in a single statement, and discusses various types of operators in Python including arithmetic and comparison operators, along with examples of their usage.

Uploaded by

vishal10thakwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

QUOTATION IN PYTHON

 Python accepts single ('), double (") and triple (''' or """)
quotes to denote string literals.
 Anything that is represented using quotations are
considered as string.
 single quotes (' ') Eg, 'This a string in single quotes’
 double quotes (" ") Eg, "'This a string in double quotes’”
 triple quotes(""" """) Eg, This is a paragraph. It is made
up of multiple lines and sentences."""
TUPLE ASSIGNMENT

 An assignment to all of the elements in a tuple using a single


assignment statement.
 Python has a very powerful tuple assignment feature that allows a
tuple of variables on the left of an assignment to be assigned values
from a tuple on the right of the assignment.
 The left side is a tuple of variables; the right side is a tuple of values.
 Each value is assigned to its respective variable.
 All the expressions on the right side are evaluated before any of the
assignments. This feature makes tuple assignment quite versatile.
 Naturally, the number of variables on the left and the number of
values on the right have to be the same.
>>> (a, b, c, d) = (1, 2, 3)
Value Error: need more than 3 values to
unpack
Example

 It is useful to swap the values of two variables.


 With conventional assignment statements, we have to use a temporary
variable. For example, to swap a and b:

Swap two numbers output


a=2
b=3
print(a,b) (2, 3)
temp = a (3, 2)
a=b
b = temp
print(a,b)
OPERATORS

Operators are the constructs


which can manipulate the value
of operands.
 Consider the expression 4 + 5 =
9. Here, 4 and 5 are called
operands and + is called
operator.
Types of operators

 Python language supports the following types of operators


 Arithmetic Operators
 Comparison (Relational) Operators
 Assignment Operators
 Logical Operators
 Bitwise Operators
 Membership Operators
 Identity Operators
Arithmetic operators
They are used to perform
mathematical operations like
addition, subtraction,
multiplication etc. Assume,
a=10 and b=5
Operator Description Example
+ Addition Adds values on either side of the a + b = 30
operator.
- Subtraction Subtracts right hand operand from a – b = -10
left hand operand.
* Multiplication Multiplies values on either side of the a * b = 200
operator.
/ Division Divides left hand operand by right b/a=2
hand operand
% Modulus Divides left hand operand by right b%a=0
hand operand and returns remainder
** Exponent Performs exponential (power) a**b =10 to the power
calculation on operators 20
// Floor Division - The division of 5//2=2
operands where the result is the
quotient in which the digits after the
decimal point are removed
Example Output

a=10 a+b= 15
b=5 a-b= 5
print("a+b=",a+b) a*b= 50
print("a-b=",a-b) a/b= 2.0
print("a*b=",a*b) a%b= 0
print("a/b=",a/b) a//b= 2
print("a%b=",a%b) a**b= 100000
print("a//b=",a//b)
print("a**b=",a**b)
Comparison (Relational) Operators

Comparison operators are used to


compare values.
It either returns True or False
according to the condition.
 Assume, a=10 and b=5
Operator Description Examples
== If the values of two operands are equal, (a == b) is true.
then the condition becomes true.
!= If values of two operands are not equal, (a!=b) is true
then condition becomes true. (a!=b) is true.
> If the value of left operand is greater than (a > b) is true
the value of right operand, then condition
becomes true.
< If the value of left operand is less than the (a < b) is true
value of right operand, then condition
becomes true.
>= If the value of left operand is greater than (a >= b) is true.
or equal to the value of right operand, then
condition becomes true.
<= If the value of left operand is less than or (a <= b) is true.
equal to the value of right operand, then
condition becomes true.

You might also like