Skip to content
Advertisement

How to select the first character on a string in python then use that first character in an if statement

JavaScript

**This should print “{name} plays banjo” because the name starts with “r” and I suspect that there is something wrong with how I selected the first character of the string and used it in an if statement. **

Advertisement

Answer

Python has a string method startswith() which will do what you need.

Replace

JavaScript

With a single if statement

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement