Lecture2 Py
Lecture2 Py
Basic
Operations
concatenation
“helloworld”
“hello” +
“world”
length of
str
len(str)
Indexing
Apna_Colle
ge
0 1 2 3 4 5 6 7 8 9 10
11
str = “Apna_College”
str = “ApnaCollege”
str[ 1 : 4 ] is “pna”
str[ : 4 ] is same as
str[ 0 : 4]
str[ 1 : ] is same
as str[ 1 : len(str) ]
Slicing
Negative Index
Apple
-5 -4 -3 - 2 -1
str = “Apple”
str[ -3 : -1 ] is “pl”
String Functions
str = “I am a coder.”
if(condition) :
Statement1
elif(condition):
Statement2
else:
Statem
entN
Conditional
Statements
Grade students based on
marks