Check if a string has special character or not

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
  1. Take a string as input.
  2. Create a string with all special characters as its value.
  3. Create a count variable and assign its value equal to zero.
  4. Use For loop to iterate over each character of the string.
  5. If the character is in a string of special characters then add 1 to the count variable.
  6. In the end, if the count variable is greater than 0 then the string has a special character.
  7. 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
				
			

remove all duplicate characters from a given string

exchange the first and last letters of the string

Leave a Comment