Variables#

Learning Objectives#

  • Understand how to create and assign variables in Julia

  • Recognize and use basic data types in Julia, including integers, floating-point numbers, strings, and booleans

  • Utilize Julia dynamic typing system for variable assignment and manipulation

  • Implement basic operations and functions with different data types

  • Print and interpret the data types of variables using Julia’s built-in functions

Overview#

Variables in Julia are created with an assignment statement. Julia uses dynamic typing, such as specifying an int below.

x = 10 
println(x)
println(x)
10
10

Basic Types#

  • Integers (Int): Represent whole numbers. Julia selects appropriate bit sizes based on the platform (e.g., Int32, Int64).

  • Floating-point numbers (Float): Used for decimal numbers. Precision can vary (e.g., Float32, Float64).

  • Strings (String): Represents text. Julia uses UTF-8 encoded strings.

  • Booleans (Bool): Represents logic. Logical data type with two states: true and false.

x = 100
println("The value of X: ", x, " with the data type: ", typeof(x))

y = 100.05 
println("The value of y: ", y, " with the data type: ", typeof(y))

name = "Julia"
println("The value of name: ", name, " with the data type: ", typeof(name))

conditional = true
println("The value of conditional: ", conditional, " with the data type: ", typeof(conditional))
The value of X: 100 with the data type: Int64
The value of y: 100.05 with the data type: Float64
The value of name: Julia with the data type: String
The value of conditional: true with the data type: Bool