Last active
November 19, 2020 19:35
-
-
Save SahbiOuali13/6d7298752cf6b45114b30a5de8e8e4d9 to your computer and use it in GitHub Desktop.
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
fruit = "banana" | |
# length of a string | |
l = len(fruit) | |
# iterating through a string | |
for letter in fruit: | |
print(letter) | |
# checking if a string or a substring exists in another | |
print("anana" in fruit) | |
# comaparing maj and min | |
fruit_upper = 'BANANA' | |
fruit_lower = 'banana' | |
print(fruit_upper > fruit_lower) # False because uppercases are lower than lowercases | |
# lower and upper methods | |
fruit_lower = fruit.lower() # lower all uppercases | |
fruit_upper = fruit.upper() # upper all lowercases | |
# find function returns the position of the string or the substring | |
print(fruit.find('na')) | |
>>2 | |
# replace function replace a substring by another one. All occurences of that substring are replaced. | |
greet = 'Hello Bob' | |
nstr = greet.repalce('Bob', 'Jane') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment