liveBook · Manning

Character

As explained in Julia as a Second Language

A character is a single textual symbol represented as a value in a programming language.

A character is a single textual symbol represented by Julia’s Char type. Write character literals with single quotes, such as 'A' or 'Y'; use double quotes for strings. Although characters occupy numeric representations in memory, Char determines which operations are valid. section 4.8 section 4.9

Characters become useful when combined with Julia’s collection and iteration tools:

  • Create arrays of characters with syntax such as ['H', 'E', 'L', 'L', 'O']. section 4.8
  • Join characters into a string with join(chars), or join a character range such as 'A':'G'. section 4.8
  • Collect a string or character range to obtain an array of Char values. section 4.8
  • Do not add two characters, but add an integer to a character to produce another character, as 'A' + 3 returns 'D'. section 4.8

Encoding pizza size

A tuple can store a pizza name, a character size, and a price: ("hawaiian", 'S', 10.5). Here 'S' is a Char, while "hawaiian" is a String. Tuples preserve each element’s type and cannot be changed. section 4.9

julia> x = Int8(65)                                           #1
65
 
julia> ch = Char(65)                                          #2
'A': ASCII/Unicode U+0041 (category Lu: Letter, uppercase)
 
julia> ch = Char(66)
'B': ASCII/Unicode U+0042 (category Lu: Letter, uppercase)
 
julia> 'A'                                                    #3
'A': ASCII/Unicode U+0041 (category Lu: Letter, uppercase)
 
julia> Int8('A')                                              #4
65

Inspect how numeric values and character literals can represent the same underlying code while retaining different Julia types. section 4.8

How Julia as a Second Language covers it

How deep it goes
Explains literals, numeric representation, arithmetic, ranges, joining, and collection, while deferring deeper type-system treatment.
Examples
Uses character literals, character arrays, ranges, joined strings, collected strings, and pizza-size tuples.
What it assumes
Assumes familiarity with numbers and basic Julia values while introducing text representation from the character level upward.
What you can do after
Build character values, combine them into strings, iterate over ranges, and distinguish Char fields from String fields.
How it connects
Connects characters with strings, arrays, tuples, ranges, iteration, and Julia’s type system.

Also explained in

Compare how 2 books explain character →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Julia as a Second Language. The section links point to the parts of the book it draws on.