Menu

A character, often shortened to char, is a data type that holds exactly one character. That single character can be a letter, a digit, a symbol or a space.

Each of these is one character: "Z", "6", "#" and "$". In Python you write a character inside quotation marks, for example "g". The quotes are not part of the character; they show where the value starts and ends.

A char cannot hold more than one character. "AB" contains two characters, so it is a string rather than a char. A char is always exactly one character long, while a string can contain zero or more characters. An empty string "" is valid, but it is not a character.

ValueCharacter?Why
"W"YesOne letter
"8"YesOne digit
"&"YesOne symbol
"_"YesOne symbol
"W8"NoTwo characters, so a string
""NoEmpty string, zero characters

Characters in Python

The specification lists char as a primitive data type, so if a question asks for the data type of a value such as "M", the answer is char. Python has no separate char type, though: you write the character in quotes and it is held as a string of length one.

You can check the length with len(). For example, len("M") gives 1, confirming a one-character string. This matters when you choose an initial value: to store a player's initial, set the variable to a one-character string such as "M", not to a number or a longer piece of text.

Practise this