What a Char Stores
A character (char) is a single symbol: a letter, digit or punctuation mark. In memory it is stored as a code such as ASCII. Edexcel lists char as a primitive data type alongside integer, real and Boolean.
Python does not have a separate char type. A one-character string such as "A" is how you write a char in the Programming Language Subset. Treat length 1 as a character; a longer string is a structured type, not a primitive char.
Which value is a character?
{"answers": {"A": "'%'", "B": "3.14", "C": "True", "D": "\"hello\""}, "question_text": "Which value is a character?", "correct_answer": "A"}
Char versus String
Char
One symbol. Example: 'Y' for a yes/no flag. You can compare it with == and you never loop through its letters.
String
A sequence of characters. Example: "YES". You can take length, a substring, or change case. Putting a whole name in a char would be the wrong type.
A [[char]] holds one symbol. A [[string]] holds a sequence of characters.
{"cloze_text": "A [[char]] holds one symbol. A [[string]] holds a sequence of characters."}
{"keyword": "character", "definition": "A primitive data type that stores a single letter, digit or punctuation mark"}
Question Type: fill in the blanks
{"paragraph": "In Python a char is written as a string of [[length]] 1, for example \"A\"."}
{"paragraph": "In Python a char is written as a string of [[length]] 1, for example \"A\"."}
Question Type: short answer
{"answer": "It contains more than one symbol; a char stores a single symbol.", "rubric": {"0": "Incorrect or no response", "1": "Partial credit", "2": "It contains more than one symbol; a char stores a single symbol."}, "question": "Why is \"hello\" not a character?"}
{"answer": "It contains more than one symbol; a char stores a single symbol.", "rubric": {"0": "Incorrect or no response", "1": "Partial credit", "2": "It contains more than one symbol; a char stores a single symbol."}, "question": "Why is \"hello\" not a character?"}
Complete! Ready to test your knowledge?
Character data type
- What a Char Stores
- Char versus String