Skip to content

Commit 0e50ab7

Browse files
committed
Create solution for "Format a string"
1 parent b72e809 commit 0e50ab7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

string_format.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def main():
2+
string = input("String: ")
3+
print("Lowercase:", string.lower())
4+
print("Is in title case:", string.istitle())
5+
# Note for below: position is zero-based, essentially the first letter is position 0
6+
print("Is the third letter 'a'?", string[2] == 'a')
7+
position = string.find('e') + 1 # By storing the string.find() result, the code only has to find the position once
8+
print("Letter 'e' position", "Not present" if position == 0 else position) # Print position if present
9+
10+
11+
if __name__ == "__main__":
12+
main()

0 commit comments

Comments
 (0)