0
0
Pythonprogramming~10 mins

String length and membership test in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
String length and membership test
๐Ÿ“– Scenario: You are working on a simple program that checks details about a username entered by a user. This is common when signing up for websites or apps.
๐ŸŽฏ Goal: You will create a program that stores a username, checks if it contains a special character, and then prints the length of the username and whether the special character is present.
๐Ÿ“‹ What You'll Learn
Create a variable called username with the exact value 'user_123'.
Create a variable called special_char with the exact value '_'.
Use the in keyword to check if special_char is in username and store the result in a variable called has_special.
Use the len() function to find the length of username and store it in a variable called length.
Print the values of length and has_special exactly as shown.
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Checking usernames or passwords for special characters and length is common in sign-up forms to ensure security and proper formatting.
๐Ÿ’ผ Career
Understanding string operations like length and membership tests is essential for roles in software development, quality assurance, and data processing.
Progress0 / 4 steps
1
Create the username variable
Create a variable called username and set it to the string 'user_123'.
Python
Need a hint?

Use the equals sign = to assign the string 'user_123' to username.

2
Create the special character variable
Create a variable called special_char and set it to the string '_'.
Python
Need a hint?

Assign the underscore character '_' to the variable special_char.

3
Check for special character and find length
Create a variable called has_special that is True if special_char is in username, otherwise False. Also create a variable called length that stores the length of username using the len() function.
Python
Need a hint?

Use the in keyword to check membership and len() to get string length.

4
Print the results
Print the value of length and then print the value of has_special on separate lines.
Python
Need a hint?

Use two print() statements, one for length and one for has_special.