How to count the total number of punctuation characters in a string with Python

1 Answer

0 votes
str = "Python is an interpreted high-level general-purpose programming language."

count = 0
for i in range (0, len (str)):   
    if str[i] in ('!', "," ,"\'" ,";" ,"\"", ".", "-" ,"?"):  
        count = count + 1 
              
print(count)




'''
run:

3

'''

 



answered Sep 27, 2021 by avibootz
...