Write a Python program to check whether a string contains special characters.
Input
"python$$#sqatools", "python"
Output
python$$#sqatools -> has special characters ['$', '$', '#']
python -> no special characters []
Approach
A special character is not alphanumeric and not a space.
Solution
Python
fortextin["python$$#sqatools","python"]:special=[chforchintextifnotch.isalnum()andnotch.isspace()]print(text,"->","has special characters"ifspecialelse"no special characters",special)
Output
python$$#sqatools -> has special characters ['$', '$', '#']
python -> no special characters []
Learn the concept
New to this topic? Read the lesson, then come back.