<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 provides a concise overview of standard types for text representation, covering the fundamental concepts of introducing text and string interpolation. Although in-depth string analysis isn't necessary, understanding these basic principles are essential for using Julia effectively.
The Char
type is used to represent individual characters. As it supports Unicode characters, it encompasses not only numbers and letters, but also a wide range of symbols. A character x
is introduced by using the syntax 'x'
, as shown below.
# x equals the character 'a'
x = 'a'
# 'Char' allows for Unicode characters
x = 'Îē'
y = 'ð'
Notice that characters necessarily must be enclosed in single quotes ' '
, or otherwise Julia will interpret the expression as a variable. This holds even for symbols like ð.
# 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 type String
, which is an ordered collection of characters that can 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 expressions or variables within a string, and then evaluate those expressions or replace the variables with their values.
To interpolate an expression into a string, you simply prefix it 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
x = "There are $(number_students) students in the course"
x
number_matches = 50
goals_per_match = 2
x = "Last year, Messi scored $(number_matches * goals_per_match) goals"
x