In this program, we will take a string as input and check if a string has special character or not.
Steps to solve the program
- Take a string as input.
- Create a string with all special characters as its value.
- Create a count variable and assign its value equal to zero.
- Use For loop to iterate over each character of the string.
- If the character is in a string of special characters then add 1 to the count variable.
- In the end, if the count variable is greater than 0 then the string has a special character.
- Print the output.
#Input strings
string = "python$$#sqatools"
#Special characters
s ='[@_!#$%^&*()<>?/\|}{~:]'
count = 0
for char in string:
if char in s:
count += 1
#Printing output
if count > 0:
print("Given string has special characters")
else:
print("‘Given string does not has special characters")
Output :
Given string has special characters