Skip to Main Content
Blog

Count Characters in Python

Count Characters in Python

from textwrap import dedent


def main():
	"""
	Counts the number of letters, uppers, lowers, digits and symbols.
	"""

	text = input("Enter string: ")

	a, l, u, d, s = 0, 0, 0, 0, 0
	for c in text:
		if c.isdigit():
			d += 1
		elif c.islower():
			l += 1
		elif c.isupper():
			u += 1
		else:
			s += 1
	a = l + u

	print(
		dedent(
			f"""\
			Letters: {a}
			Uppers:  {u}
			Lowers:  {l}
			Digits:  {d}
			Symbols: {s}
			"""
		)
	)