HTMLify

Python - String Methods
Views: 10 | Author: djdj
name = "Dj UPraiTY"
sub = "Dj"
print(len(name)) #length of the string
print(name[0:5]) #display string starting position to given position

print(str.capitalize(name)) #only first character is uppercase baki ke lowercase
print(str.lower(name)) #all string character convert to lowercase
print(str.upper(name)) # all string character convert to uppercase
print(str.title(name)) #convert first character of all words is capital
print(str.swapcase(name)) #swap case of the character lower to upper & upper to lowercase
print(str.casefold(name)) #iska pata nahi

print(name.center(15, '/')) #iska use string ko center me or length ke hisab se koi bhi char use kar sakte he 
print(name.ljust(20, '*')) #isme string text left me hogi or char right me 
print(name.rjust(13, '@'))

print(name.count(sub)) #isme name ke ander sub ko coiunt karna he kitni bar he wo words
print(name.find(sub)) #isme name me sub find hota he or apni position batana he
print(name.replace('D', 'm')) #replace any char to another

Comments