# Noemi Cabrera
# 25 October 2021
# In this lesson, I learned how to access substrings(parts of a string) using different index
# methods. You can use [start:stop] to indicate the start and end index of the string section you want
# to slice. Also, if the start index is not indicated, the default index would be 0 - [:stop]. But if you
# want to return up to a certain index, you use [start:]. This indicates the start and prints up to the
# last character. Lastly, there is the step slice. For example, [::2] indicates the size of the step is 2.
# The default start is index 0 and then steps to every other character in the string.
# The difficulties I had were with the last Task were I had to reverse a section of the string. When I
# tried to print the letters spanning indexes 3 to 6 of long_word in Reverse, the result was blank.T fix
# this, I placed the normal slice into a variable, and then printed the variable with a -1 slice to
# reverse the word.
# [ To acess a certain string section we use index slicing, which uses square brackets. In this case
# the section of characters 3 through 5 is accesed by writing the index start, which is 2, and the stop
# index, which is 5, in square brackets. ] review and run example
# assign string to student_name
student_name = "Colette"
# addressing the 3rd, 4th and 5th characters using a slice
print("slice student_name[2:5]:",student_name[2:5])
# [ In this code, the section of characters 3 through 5 of "Colette" is accesed by writing the index
# count of each character in square brackets.] review and run example
# assign string to student_name
student_name = "Colette"
# addressing the 3rd, 4th and 5th characters individually
print("index 2, 3 & 4 of student_name:", student_name[2] + student_name[3] + student_name[4])
# [ In this code, the section of characters 3 through 11 is accesed by writing the index start, which is 2,
# and the stop index, which is 11, in square brackets.] review and run example
long_word = 'Acknowledgement'
print(long_word[2:11])
print(long_word[2:11], "is the 3rd char through the 11th char")
print(long_word[2:11], "is the index 2, \"" + long_word[2] + "\",", "through index 10, \"" + long_word[10] + "\"")
# [In this code, the section of characters 5 through 7 is accesed by writing the index start, which is 4
# and the stop index, which is 7, in square brackets. The section of characters 12 through 14 is accesed
# by writing the index start, which is 11, and the stop index, which is 14, in square brackets.]
# slice long_word to print "act" and to print "tic"
long_word = "characteristics"
print(long_word[4:7])
print(long_word[11:14])
# [ In this code, the section of characters 4 through 11 is accesed by writing the index start, which is 3
# and the stop index, which is 11, in square brackets. ] slice long_word to print "sequence"
long_word = "Consequences"
print(long_word[3:11])
# [ In this code, the 1st, 2nd, and 3rd character of 'Collete' is accessed by writing a colon and the stop
# index, which is not included, in brackets. In this case placing 3 as the index count will print the
# indexes 0,1,and 2. ] review and run example
student_name = "Colette"
# addressing the 1st, 2nd & 3rd characters
print(student_name[:3])
# [ IN this code, the first half of "Consequences" is accessed by writing a colon and the stop
# index 6, which is not included, in brackets. The section "Conseq" will print.]
# print the first half of the long_word
long_word = "Consequences"
print(long_word[:6])
# [ In this code, the 4th, 5th, 6th and 7th characters of 'Colette' are accessed by writing the index
# count 3 and a colon after it. This would print all the indexes starting at 3 until the last one, which
# is 6] review and run example
student_name = "Colette"
# 4th, 5th, 6th and 7th characters
student_name[3:]
# [ This code will print from index 6 until the last index of long_word. This prints the 2nd half of
# "Consequences". ] print the second half of the long_word
long_word = "Consequences"
print(long_word[6:])
# [ When there is no value included in slice, the default start is the 1st character and the end is the
# last character.Therefore, the entire string "colette" prints. ] review and run example
student_name = "Colette"
# return all
print(student_name[:])
# [ In this case, the step index slice method is used. The start is the 1st character, C, and the end is
# the last character, e. Since the step is 2, wihch is indicated after the added colon, the letters are
# skipped by 2 starting with the 1st character. "Clte" will print as a result ] review and run example
student_name = "Colette"
# return every other
print(student_name[::2])
# [In this code, an start index of 1 for the step slice is indicated. Starting from index 1, the letters
# are skipped by 2. The end index is not indicated, so it's still the last character in the string. ]
# review and run example
student_name = "Colette"
# return every third, starting at 2nd character
print(student_name[1::2])
# [ In this code, a start index of 1 and the end index of 9 (not included) for the step slice is
# indicated. Starting from index 1, the letters are skipped by 2 until it reaches index 8. ]
# review and run example
long_word = "Consequences"
# starting at 2nd char (index 1) to 9th character, return every other character
print(long_word[1:9:2])
# [ In this code, the start or end index for the slice is not indicated, which means the default start
# is the 1st character of "Acknowledge" and the default end is the last character. Starting from index 0,
# the letters are skipped by 3 until it reaches the last index. ]
# print the 1st and every 3rd letter of long_word
long_word = "Acknowledgement"
print(long_word[::3])
# [ In this code, a start index of 2 for the step slice is indicated. Starting from index 2,
# the letters are skipped by 3 until it reaches the last index. ]
# print every other character of long_word starting at the 3rd character
long_word = "Acknowledgement"
print(long_word[2::])
# [In this code, a step of -1 is used. Since the start or end index is not indicated, the -1 step starts
# with the last character ad ends ith the 1st character. The string is reversed.]
# review and run example of stepping backwards using [::-1]
long_word = "characteristics"
# make the step increment -1 to step backwards
print(long_word[::-1])
# [ In this code, a step of -1 is used. The step starts with index 6, since it's indicated, and would
# end with the 1st character because the string is reversed and no end index is indicated. ]
# review and run example of stepping backwards using [6::-1]
long_word = "characteristics"
# start at the 7th letter backwards to start
print(long_word[6::-1])
# [The string "stressed" is reversed because the step of -1 is used. ] reverse long_word
long_word = "stressed"
print(long_word[::-1])
# [The index start of the step string slice is indicated. Therefore, the string is reversed from index
# 4 and going backwards until it reaches index 0. ] print the first 5 letters of long_word in reverse
long_word = "characteristics"
print(long_word[4::-1])
# [ The index start is 0 and the end is 4 (end is not included) ] print the first 4 letters of long_word
# [ A step slice is used. The index start is 3 and the end is 0. The step is -1 so that the word can be
# reversed. ] print the first 4 letters of long_word in reverse
# [A step slice is used. The index start is 0 and the end is -5. The step is -1 so that the word can be
# reversed. ] print the last 4 letters of long_word in reverse
# [threetosix contains the index slice without reversing the word. Then, to reverse it, I did a step
# slice with the variable to reverse the string] print the letters spanning indexes 3 to 6 of long_word
# in Reverse
long_word = "timeline"
print(long_word[:4])
print(long_word[3::-1])
print(long_word[:-5:-1])
threetosix = long_word[3:6]
print(threetosix[::-1])