Sunday, November 22, 2020

Python Basic String opetations

Python is fast emerging as a programming language, so In this post I will try to explain few python String operations required for a novice learner.


if __name__ == '__main__':
name = "Mahendra"
# Check if String is lowercase, similarly we can check for uppercase and title case
print(name.islower())
# Convert string to lowercase
print(name.lower())
# Convert string to uppercase
print(name.upper())
# Count a character in a string
print(name.count('a'))
# Delete a character from String
print(name.replace('a', ''))
# Check if a character is present in String
print('a' in name)
# Check if a substring is present in String
print('Mahen' in name)


No comments:

Post a Comment