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 trialSun Min
2,941 Pointsjava in javascript
I am working on containment.
i saw teacher's note that has example of
"java" in "javascript" would give back True.
5 in [3, 4, 1] would give back False.
why is that?
1 Answer
Ryan S
27,276 PointsHi Sun,
Both strings and lists are iterable, so you can loop through their contents to check and evaluate various things. In a string, you would loop through the letters, in a list, the list items.
So if you were to check to see if the letters "java" were in the string "javascript", python would evaluate that as True because it is. But the letters have to be in the correct order. If you were to check for "jvaa" in "javascript", for example, it would return False because although the letters exist, they don't exist in that order.
With the list, you would check to see if the number 5 exists in the the list [3, 4, 1]. Since it does not, it would return False.
Hope this clears things up.
Sun Min
2,941 PointsSun Min
2,941 PointsThank you!