Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions 04_Day_Strings/day_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,19 @@
print(challenge.expandtabs()) # 'thirty days of python'
print(challenge.expandtabs(10)) # 'thirty days of python'

# find(): Returns the index of first occurrence of substring
# find(): Returns the index of the first occurrence of a substring.
# Returns -1 if the substring is not found.

# index(): Returns the index of the first occurrence of a substring.
# Raises a ValueError if the substring is not found.

challenge = 'thirty days of python'
print(challenge.find('y')) # 5
print(challenge.find('th')) # 0

print(challenge.find('y')) # 5
print(challenge.find('th')) # 0

print(challenge.index('y')) # 5
print(challenge.index('th')) # 0

# format() formats string into nicer output
first_name = 'Asabeneh'
Expand All @@ -133,11 +141,6 @@
result = 'The area of circle with {} is {}'.format(str(radius), str(area))
print(result) # The area of circle with 10 is 314.0

# index(): Returns the index of substring
challenge = 'thirty days of python'
print(challenge.find('y')) # 5
print(challenge.find('th')) # 0

# isalnum(): Checks alphanumeric character

challenge = 'ThirtyDaysPython'
Expand Down