0% found this document useful (0 votes)
6 views

Lecture 3 Notes

Basics of Python

Uploaded by

yogesh200512
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lecture 3 Notes

Basics of Python

Uploaded by

yogesh200512
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Notes By: - Prasad Adsule

Lecture No. 3
Sr.
Content Description Example
No.
>
Greater than:
x>y
True if left operand is
greater than the right.
False if left operand is
smaller than the right.
<
Less than:
x<y
True if left operand is
Less than the right.
False if left operand is
Relational Greater than the right.
1) Operators
>, >=, <, <= >=
Greater than or equal
to:
x >= y
True if left operand is
greater than or equal to
the right

<=
Less than or equal to:
x <= y

True if left operand is


less than or equal to
the right

==
Equal to:
x == y
True if both operands
Equality are equal
2) Operators
!=
== , != Not Equal to:
x != y
True if both operands
are not equal
and

x and y
True if both the
operands are true

Logical Operators
3) or
and, or, not x or y
True if either of the
operands is true

not
not x
True if operand is false
False if operand is True

=
Equal to

Assign value of right


side of expression to
left side operand

Assignment
+=
operator Subtract and assign
=
4) Add right operand to
+=
-= left operand and then
assign addition value to
left operand

-=
Subtract and assign

Subtract right operand


from left operand and
then assign subtraction
value to left operand
*=
Multiply and assign

Multiply right
operand with left
operand and then
assign Multiplication
value to left operand

/=
Divide and assign

Divide left operand by


right operand and
then assign division
value to left operand

Assignment
operator //=
*= Divide(floor)and
4) /= assign:
//=
%= Divide left operand
**= with right operand
and then assign the
value(floor) to left
operand

%=
Modulus and assign:

Takes modulus using


left and right
operands and assign
result to left operand

**=
Exponent and assign:
Calculate exponent
value using operands
and assign value to
left operand
String = A sequence of
characters

-We can create a


string by enclosing
the characters in
single-quotes or
5) string
double- quotes.
-Python also provides
triple-quotes to
represent the string,
but it is generally used
for multiline string
or docstrings.

a)
You cannot use single
quote inside single
quote.
Use \ before inside
single quote for this.

Rules for use of


Single, double and
6)
triple quotes in
String a)
You cannot use
double quote inside
double quote.
You can use single
quote inside double
quote.
Use \ before inside
double quote for this.
(\ means escape next
quote.)
To access individual characters of string.
Positive Indexing

indexing of the strings


starts from 0 and
assigned from left to
right
Negative Indexing

it starts from the


rightmost character,
which is indicated as
7) Indexing
-1. The second
rightmost index
indicates -2, and so
on.
For indexing use []

By referencing index
numbers, we can
isolate one of the
characters in a string.
We do this by putting
the index numbers in
square brackets.
We can also call out a range of characters (Group of
characters) from the string.
When slicing strings, we are creating a substring, which is
essentially a string that exists within original string.
With slices, we can
call multiple character
values by creating a
range of index
numbers separated by
8) Slicing
a colon [x:y]

When constructing a
slice, as in [2:4], the
first index number is
where the slice starts
(inclusive), and the
second index number
is where the slice ends
(exclusive)
If nothing is specified
[ :y]= Will start from
0th index up to
y(exclusive)
[x: ]=Will start from
x(inclusive) up to last.
8) Slicing
Slicing using
[x:y:z] format
X= start (inclusive)
y= end (exclusive)
Z= jump to next Zth
character.
Or skip (z-1) numbers

[ x: y: -z]
From Xth character to
Yth character by
skipping (-Z+1)
characters.
9) String Reversing

[ : : -Z]
Start from rightmost
end to leftmost by
skipping
(-z+1)characters

You might also like