Skip to content

Instantly share code, notes, and snippets.

@SahbiOuali13
Last active November 19, 2020 19:35
Show Gist options
  • Save SahbiOuali13/6d7298752cf6b45114b30a5de8e8e4d9 to your computer and use it in GitHub Desktop.
Save SahbiOuali13/6d7298752cf6b45114b30a5de8e8e4d9 to your computer and use it in GitHub Desktop.
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