<function>
or <operator>
).
This is just notation, and the symbols <
and >
should not be misconstrued as Julia's syntax.
Action | Keyboard Shortcut |
---|---|
Previous Section | Ctrl + π |
Next Section | Ctrl + π |
List of Sections | Ctrl + z |
List of Subsections | Ctrl + x |
Close Any Popped Up Window (like this one) | Esc |
Open All Codes and Outputs in a Post | Alt + π |
Close All Codes and Outputs in a Post | Alt + π |
Unit | Acronym | Measure in Seconds |
---|---|---|
Seconds | s | 1 |
Milliseconds | ms | 10-3 |
Microseconds | ΞΌs | 10-6 |
Nanoseconds | ns | 10-9 |
This section presents types for text representation, distinguishing between characters and strings. The coverage will be concise, as the website won't focus on string analysis. However, a minimal coverage is necessary as string variables are important for tasks like specifying paths, saving files, and other core functionalities.
In Julia, the Char
type is used to represent individual characters. A character x
is defined by using single quotes, as in 'x'
. Given its support for Unicode characters, Char
encompasses not only numbers and letters, but also a wide range of symbols. This is shown below.
# x equals the character 'a'
x = 'a'
# 'Char' allows for Unicode characters
x = 'Ξ²'
y = 'π'
Notice that characters must be enclosed in single quotes ' '
, even for symbols like π. Otherwise, Julia will interpret the expression as a variable.
# any character is allowed for defining a variable
π = 2 # π represents a variable, just like if we had defined x = 2
y = π # y equals 2
z = 'π' # z equals the character π
We'll rarely use the type Char
directly. Instead, we'll work with the so-called type String
. This is an ordered collection of characters, making it possible to represent text.
Strings can be defined through either double quotes " "
or triple quotes """ """
. The latter is particularly convenient for handling newlines, such as when the text has to span multiple lines. [note] For more on the differences between double and triple quotes, see here
x = "Hello, beautiful world"
x = """Hello, beautiful world"""
String interpolation allows you to embed Julia code within a string, which is then evaluated and replaced in the string with its value.
To interpolate an expression, you must simply prefix the string with the $
symbol. If the expression contains spaces, you'll need to enclose it in curly braces, like $()
. Both cases are exemplified below.
number_students = 10
output_text = "There are $(number_students) students in the course"
x
number_matches = 50
goals_per_match = 2
output_text = "Last year, Messi scored $(number_matches * goals_per_match) goals"
x