Welcome to Python, and welcome to Code Review.
An instance of a class, where only one method is ever called, is not a good class. Instead, use functions.
a = input("Enter a string: ")
Class Constants & Members
If you do create a class, and that class has some global constant data, store that on the
class itself, not on the instances of the
Constants should have
UPPERCASE_NAMES, to distinguish them from non-constant data. Moreover, if the data is constant, where possible use non-mutable objects, such as
(..., ..., ...)) over
[..., ..., ...]).
Non-public members of a class should begin with a single underscore.
VOWELS = ("a", "e", "i", "o", "u")
def __init__(self, string):
self._string = string
When attempting to compare strings (or characters) case-insensitively, use
.casefold() instead of
.lower(). This properly handles many additional oddities, such as the German
ß which is equivalent to
x in y
Testing for existence of an item in a container is easily done with the
in operator. For example, this code:
for vowel in vowels:
if letter == vowel:
counter += 1
can be re-written more efficiently as:
if letter in vowels:
count += 1
A String is a Container
It could even be re-written as:
if letter in "aeiou":
count += 1
since a string is simply a container of letters.
Non-Vowels are not necessarily Consonants
Many characters which are not vowels are also not consonants, such as
. to name a few.
Avoid Name Shadowing
string is not a good variable name, because a module named
string exists, and can be imported, and doing so results in the meaning of
string changing depending on what is in scope.
It is even reasonable that you’d
import string in this program, to get convenient access to all of the