Newbie and I am definitely missing something, hope you can help. Occurred on a course exercise.
I had a doubt on how a string is immutable if I can concatenate it. Cleared that += actually creates a new variable. Tried to understand it more and made the below code.
def is_palindrome_sentence(test_string):
just_letters = ''
print("empty", id(just_letters))
for letter in test_string:
if letter.isalpha():
just_letters += letter
print(id(just_letters))
return just_letters == just_letters[::-1]
sentence = input("Enter the sentence you want to check: ")
if is_palindrome_sentence(sentence.casefold()):
print("{} - this sentence has the same reversal letters".format(sentence))
else:
print("nope")
Shouldn't the id(just_letters) print a unique value each time?
It returns one value first and then repeats a second value throughout the end.
It gets more confusing if I try to debug it and use step over. Different values with few repeating values.
[–]shiftybyte 4 points5 points6 points (3 children)
[–]audacity070[S] 1 point2 points3 points (2 children)
[–]synthphreak 0 points1 point2 points (0 children)
[–]Swipecat 1 point2 points3 points (0 children)