# Julia

## Basics

- To import packages, use
`using`

or`import`

. - Install package via Julia’s package manager, in the Julia’s console by typing
`]`

and then`add Flux`

- Equivalently, via the
`Pkg`

API:

```
import Pkg
Pkg.add("Flux")
```

- Uninstall package via Julia’s package manager, in the Julia’s console by typing
`]`

and then`remove Flux`

or`rm Flux`

- To go back to Julia’s interpreter, click backspace key.

```
answer = 42 # Variable assignments
x, y, z = 1, [1:10;], "Hello World" # Multiple assignment
z, y = y, z # swap x and y
const pi = 3.14 # Constant declaration
i = 1 # End-of-line
#=
Delimited Comment
OR Multi-line comment
=#
0 < i < 3 # Chaining
5 < x != i < 5
# function definitions
function add_one(i)
return i+1
end
```

## Operators

```
+, -, *, /, % # Basic arithmetic
2^3 # Exponentiation
3/12 # Fractional division
7\3 # Inverse division. It's same as 1/(7/3)
!true # Logical negation
1 == 2 # Equality
1 != 2 # Inequality
1 ≠ 2 # Inequality where you can use unicode symbols
1 < 2 # Less than
2 > 3 # Greater than
1 <= 2 # Less than or equal to
1 ≤ 2 # use of unicode
1 >= 2 # Greater than or equal to. OR ≥
[1, 2, 3] .+ [1, 3, 3] == [1+1, 2+3, 3+3] == [2, 5, 6] # Element-wise addition operation
[1, 2, 3] .* [1, 2, 3] == [1, 4, 9] # Element-wise multiplication operation
isnan(NaN) # Check for if NaN is a REALLY Not a Number (NaN)
isnan(1/0) # Check for if Infinity is a NaN
a, b = 1, 0
a == b ? "Equal" : "Not equal" # Ternary operator
a && b # Logical AND operator
a || b # Logical OR operator
a === b # Object equivalence OR strict equality
#The ?() method allows us to quickly explore documentation in the most depth possible. For example:
?(push!)
```

Permalink athttps://www.physicslog.com/cs-notes/julia

Published onMay 28, 2021

Last revised onJul 2, 2023

References