Easy Tutorial
❮ Julia Dictionaries Sets Julia Array ❯

Julia Basic Syntax

Variables

Variables originate from mathematics and are abstract concepts in computer languages that can store calculation results or represent values.

Variables can be accessed by their names.

Julia language variable names consist of letters, numbers, and underscores _, with the first character not being a number.

Variable names are case-sensitive.

Using variables in Julia is straightforward; simply assign a value to them, as shown in the example below:

Example

# Assign 10 to variable x
x = 10

# Use the value of x for calculation
x + 1
11

# Assign a string to variable site_name
site_name = "tutorialpro"

# Floating-point data
marks_math = 9.5

In the interactive command environment, the output is as follows:

From the examples, we see that unlike other programming languages such as C++ and Java, Julia does not require specifying variable types; it can automatically infer the type of the object on the right side of the equal sign.

Naming Conventions


Comments

Julia supports single-line and multi-line comments.

Single-line comments in Julia start with #, for example:

Example

# This is a single-line comment
# This is another single-line comment
println("Hello World!")

Multi-line comments are enclosed with #= and =#, for example:

Example

#= 
1. This is a single-line comment
2. This is another single-line comment
=#
println("Hello World!")
❮ Julia Dictionaries Sets Julia Array ❯