So, I am trying to create a program which counts the number of characters in a string which the user inputs, but I want to discard any spaces that the user enters.
I can propose a few versions.
You can replace each space with an empty string and calculate the length:
len(mystr.replace(" ", ""))
You can calculate the length of the whole string and subtract the number of spaces:
len(mystr) - mystr.count(' ')
Or you can sum the lengths of all substrings after splitting the string with spaces:
sum(map(len, mystr.split(' ')))