Lecture2 Py738
Lecture2 Py738
Basic Operations
concatenation
length of str
len(str)
Indexing
Apna_College
0 1 2 3 4 5 6 7 8 9 10 11
str=“Apna_College”
str[0]is‘A’,str[1]is‘p’...
str[0]=‘B’#notallowed
Slicing
Accessing parts of a string
str=“ApnaCollege”
str[1:4]is“pna”
Apple
-5-4-3-2-1
str=“Apple”
str[-3:-1]is“pl”
StringFunctions
str=“Iamacoder.”
str.capitalize()#capitalizes1st char
if(condition):
Statement1
elif(condition):
Statement2
else:
StatementN
ConditionalStatements
Grade students based on mark
marks>=90,grade=“A”
= “B”
80>marks>=70,grade=“C
” 70>marks,grade=“D”
Let‘sPractice
WAP to check if a number entered by the user is oddoreven.