This lecture you will learn python String properties and Methods!
String properties and Methods
Diff between – function and method
Function and methods both are mostly same where as once we write a function within a class and is associated with class objects it is called method, without class it is a function.
course = 'Python for Beginners'
print(len(course))
print(course.upper())
print(course.lower())
print(course)
Index of the Print statement
Using Find method to identify the index
print(course.find('P'))
print(course.find('o'))
output: 0 and 4 as order statements
If you pass capital “O” which is not available in out statement shows -1 negative
print(course.find('O'))
-1
If you pass a sequence of characters string to find
print(course.find('Beginners'))
11
Index will begins and position is 11
replace method
course = 'Python for Beginners'
print(course.replace('Beginners', 'Absolute Starters'))
output:
Python for Absolute Starters
Case change and try
print(course.replace('beginners', 'Absolute Starters'))
output:
Python for Beginners
Even you can replace with single letter with case
print(course.replace('P', 'M'))
output:
Mython for Beginners
Character existence or sequence of character
print('Python' in course)
True
print('python' in course)
False
Exact sequence letter not available
It will produce Boolean Express i.e. true / false
All you learn here about standard and built-in python methods are avilable in python programming language.
Difference between find method and in operator is
find method returns Index of that sequence of characters
in operator produces Boolean value
recap:
len()
course.upper()
course.lower()
course.title()
course.find()
course.replace()
‘. . .’ in course