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
Ben Bassler
1,806 PointsHow can I check the length of a string in an If-Statement?
"Can you please raise a ValueError if the product_idea is less than 3 characters long? product_idea is a string.". That was the question... but how do I check the length of a string?
2 Answers
diogorferreira
19,363 PointsThere's a function, len() that returns back the length of the string you provided. This link might help you out..
So you might be able to do
if len(product_idea) < 3:
raise ValueError('Return something like, Need a longer product idea!')
<noob />
17,063 PointsHi!, u do it like that:
u use the len() method. for example : if len(product_idea) < 3:
Ben Bassler
1,806 PointsYup this worked! Thanks for your help.
Ben Bassler
1,806 PointsBen Bassler
1,806 PointsPerfect, thanks for helping out! :)