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

Module 3 - Strings, Operators, and Controls

Uploaded by

merryfil.adolfo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Module 3 - Strings, Operators, and Controls

Uploaded by

merryfil.adolfo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Click to edit Master title style

Strings,
Operators, and
Controls
Module 3

1
Click to edit Master title style
Outline:

• More on Strings
• Operators
• Control Structures

2
Click toMethods
String edit Master title style

• str.capitalize() Returns the copy of the string with its first character
capitalized and the rest of the letters are in lowercase
• string.casefold() Returns a lowered case string. It is similar to the
lower() method, but the casefold() method converts more characters into
lower case.
• string.center() Returns a new centered string of the specified length,
which is padded with the specified character. The deafult character is
space.
• string.count() Searches (case-sensitive) the specified substring in the
given string and returns an integer indicating occurrences of the substring.
• string.endswith() Returns True if a string ends with the specified
suffix (case-sensitive), otherwise returns False.
3
Click toMethods
String edit Master title style

• string.find() Returns the index of the first occurence of a substring


in the given string (case-sensitive). If the substring is not found it
returns -1
• string.index() Returns the index of the first occurence of a substring
in the given string.
• string.islower() Checks whether all the characters of a given string
are lowercased or not. It returns True if all characters are lowercased
and False even if one character is uppercase.
• string.istitle() Checks whether each word's first character is upper
case and the rest are in lower case or not. It returns True if a string is
titlecased; otherwise, it returns False. The symbols and numbers are
ignored.
4
Click toMethods
String edit Master title style

• string.isupper() Returns True if all characters are uppercase and


False even if one character is not in uppercase.
• string.join() Returns a string, which is the concatenation of the
string (on which it is called) with the string elements of the
specified iterable as an argument.
• string.lower() Returns the copy of the original string wherein all
the characters are converted to lowercase.
• string.upper() Returns a string in the upper case. Symbols and
numbers remain unaffected.
5
Click to edit[08]
Simulation Master title style

6
Click to Operators
Python edit Master title style

• Operators are special symbols that perform some operation on


operands and returns the result.
• For example, 5 + 6 is an expression where + is an operator that
performs arithmetic add operation on numeric left operand 5 and
the right side operand 6 and returns a sum of two operands as a
result.
• Python includes the operator module that includes underlying
methods for each operator. For example, the + operator calls the
operator.add(a,b) method.

7
Click to Categories
Python edit Masterof
title style
Operators

• Arithmetic Operators
• Assignment Operators
• Comparison Operators
• Logical Operators
• Identity Operators
• Membership Test Operators
• Bitwise Operators

8
Click to editOperators
Arithmetic Master title style

• Arithmetic operators perform the common mathematical operation


on the numeric operands.
• The arithmetic operators return the type of result depends on the
type of operands, as below.
• If either operand is a complex number, the result is converted
to complex;
• If either operand is a floating point number, the result is
converted to floating point;
• If both operands are integers, then the result is an integer and
no conversion is needed.

9
ClickoftoArithmetic
List edit Master title style
Operators

10
ClickoftoArithmetic
List edit Master title style
Operators

11
ClickoftoArithmetic
List edit Master title style
Operators

12
Click to edit Operators
Assignment Master title style

• The assignment operators are used to assign values to variables.

13
Click to edit Operators
Assignment Master title style

• The assignment operators are used to assign values to variables.

14
Click to edit Operators
Assignment Master title style

• The assignment operators are used to assign values to variables.

15
Click to edit Operators
Assignment Master title style

• The assignment operators are used to assign values to variables.

16
Click to edit Operators
Comparison Master title style
• The comparison operators compare two operands and return a
boolean either True or False.

17
Click to edit Operators
Comparison Master title style
• The comparison operators compare two operands and return a
boolean either True or False.

18
Click to edit Operators
Comparison Master title style
• The comparison operators compare two operands and return a
boolean either True or False.

19
Click to Operators
Logical edit Master title style
• The logical operators are used to combine two boolean expressions. The logical operations are
generally applicable to all objects, and support truth tests, identity tests, and boolean operations.

20
Click to edit
Identity Master title style
Operators
• The identity operators check whether the two objects have the same id
value e.i. both the objects point to the same memory location.

21
Click to edit Master
Membership title style
Operators
• The membership test operators in and not in test whether the sequence has a given item or
not. For the string and bytes types, x in y is True if and only if x is a substring of y.

22
Click to Operators
Bitwise edit Master title style

• Bitwise operators perform operations on binary operands.

23
Click to Operators
Bitwise edit Master title style

• Bitwise operators perform operations on binary operands.

24
Click to Operators
Bitwise edit Master title style

• Bitwise operators perform operations on binary operands.

25
Click to edit[09]
Simulation Master title style

26
Click to -edit
Python Master
if, elif, else title style
Conditions

By default, statements in the script are executed sequentially from the


first to the last. If the processing logic requires so, the sequential flow
can be altered in two ways:

Python uses the if keyword to implement decision control.

27
Click to Syntax
Python edit Master title style

28
Click to -edit
Python Master
if, elif, else title style
Conditions

Any Boolean expression evaluating to True or False appears after the


if keyword. Use the : symbol and press Enter after the expression to
start a block with an increased indent. One or more statements written
with the same level of indent will be executed if the Boolean
expression evaluates to True.

To end the block, decrease the indentation. Subsequent statements


after the block will be executed out of the if condition.

29
Click to -edit
Python Master
if, elif, else title style
Conditions
Along with the if statement, the else condition can be optionally used
to define an alternate block of statements to be executed if the
boolean expression in the if condition evaluates to False.

30
Click to -edit
Python Master
if, elif, else title style
Conditions
Use the elif condition is used to include multiple conditional
expressions after the if condition or between the if and else
conditions.
The elif block is executed if the specified condition evaluates to True.

31
Click to -edit
Python Master
if, elif, else title style
Conditions
Python supports nested if, elif, and else condition. The inner condition
must be with increased indentation than the outer condition, and all
the statements under the one block should be with the same
indentation.

32
Click to edit[10]
Simulation Master title style

33

You might also like