Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics Functions and Looping For Looping

Why is the output "o o h"?

for letter in "You got this!":
    if letter in "oh":
        print(letter)

I don't seem to understand why the output is "o o h"? What happened to the "you got this"? And where did the extra "o" come from?

Thanks

David Garcia
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
David Garcia
Python Development Techdegree Graduate 11,254 Points

think about it like this: for every letter thats in 'you got this' and if the letter is in 'oh': then print out the letter

the if statement is checking the letters within the sentence and seeing if the letter is in the word 'oh' therefore it is printing an extra 'o' when looped. hopefully that makes it simpler its a tad bit confusing

ahhh ok ok , I understand now 👌🏽 thank you !

1 Answer

Josh Keenan
Josh Keenan
20,315 Points

comment solves this.