Python Lecture 2
Python Lecture 2
STRING
CONDITION
STRINGS
BUTEX_BEST
0123456789
• str = “BUTEX_BEST”
Negative Index
A p p l e
-5 -4 -3 -2 -1
str = “Apple”
str[ -3 : -1 ] is “pl”
STRING FUNCTIONS
str = “I am a coder.”
str.endsWith(“er.“) #returns true if string ends with substr
str.capitalize( ) #capitalizes 1st char
str.find( word ) #returns 1st index of 1st occurrence
str.replace( old, new ) #replaces all occurrences of old with new
str.count(“am“) #counts the occurrence of substr in string
LETS PRACTICE
if-elif-else (SYNTAX)
if(condition) :
Statement1
elif(condition):
Statement2
else:
StatementN
CONDITIONAL STATEMENTS