Python String properties and Methods

Python3 String properties and Methods

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
Complete python course
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  
Python data science interview questions and answers python is a high-level programming language using Data Science programs these days

Data Science

Web development course Data Science courses: Web Development
Online courseOnline Courses: Include Certification
Harisystems is optimized for learning, testing and training. courses are designed to be simplified to improve reading and basic understanding for beginners to expert level. Tutorials and examples are constantly reviewed to avoid errors, however we cannot warrant full correctness of all content. if any found need to correct write us at info@harisystems.com. we Harisystems is not responsible for any with this tutorials, While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2007-2023 by Harisystems. All Rights Reserved.
Copyright © Harisystems 2023