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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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