I am a beginner and I constantly struggle with understanding a new code because the course that I am currently going through does not explain it well. In this case, I did not understand the use of segments, and the indentation. If anyone could clarify it, I would truly appreciate it!

ipAddress = input("Please enter your IP address:\n")

segment = 1
segment_length = 0
character = ' '
for character in ipAddress:
if character == '.':
print("Segment {} contains {} characters".format(segment, segment_length))
segment += 1
segment_length = 0
else:
segment_length += 1
if character != '.':
print("Segment {} contains {} characters".format(segment, segment_length))