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