def hexdump(text, encoding='utf-8'):
text_bytes = text.encode(encoding)
for i in range(0, len(text_bytes), 16):
chunk = text_bytes[i:i + 16]
What is text_bytes[i:i + 16]
exactly doing?
def hexdump(text, encoding='utf-8'):
text_bytes = text.encode(encoding)
for i in range(0, len(text_bytes), 16):
chunk = text_bytes[i:i + 16]
What is text_bytes[i:i + 16]
exactly doing?
Maybe this will answer your question: What does list[x::y] do?
So this question might be a duplicate.
In python String is treated as a list in a sense that each character is an element of a list.
So, if
my_string = "abc"
my_list = ['a', 'b', 'c']
Iteration over my_string is seamlessly like iterating iterating over my_list. As some pointed out, see What does list[x::y] do? about this list slicing syntax
So regarding your question, text_bytes[i:i + 16] is treating text_bytes as list of its characters, slicing it, and returning the substring.
So, if we take the example above:
res_string = my_string[0:2] # == "ab"
res_list = my_list[0:2] # == ['a', 'b']