Character
Introduction / Definition
A character represents a single textual symbol such as a letter, digit, or punctuation mark. Modern systems associate characters with numeric code points, often using Unicode. A character is conceptually different from a string, which contains a sequence of characters. Character operations are important in parsing, validation, and text processing.
Syntax
'A'
'7'
'?'
Detailed Explanation
Character can be understood by identifying its purpose, the rules that govern it, and the way it affects program behavior. The concept should be separated from its particular syntax so that learners can recognize the same idea across different programming languages. A useful way to study it is to start with a small example, trace what happens step by step, and then consider the benefits and limitations. This approach builds both conceptual understanding and practical programming skill.
Example
ch = 'A'
print(ch)
print(code\_point(ch))
Output
A
65
Important Points / Notes
- Understand the purpose of character.
- Separate the concept from its particular syntax.
- Trace the example step by step.
- Consider both benefits and limitations.
- Use the concept only when it improves program clarity or correctness.
Mini Practice Question
What is the difference between a character and a string?