Char (character)
In short: A char is a single character, such as 'A', '7' or 'ä'. Internally it is a number, the code of the character.
In more detail: In Java char is a 16-bit value (UTF-16 unit), in C usually 8 bits (ASCII/extensions). Because characters are numbers you can calculate with them: 'a' + 1 gives 98, as char 'b'. A string is a sequence of chars.
In detail
- Notation: single characters in single quotes
'A', strings in double quotes"AB". - ASCII:
'A'=65,'a'=97,'0'=48. Digit to number:'7' - '0'is 7. - Unicode: characters outside the basic range (emojis) take two chars in Java (surrogate pair), so use
codePoint. - Useful methods:
Character.isDigit,isLetter,toUpperCase. - Python: has no char type, a character is a string of length 1.
- Escape: special characters like
'\n', see Escape sequences.