YouTip LogoYouTip

Julia Basic Syntax

# Julia Basic Syntax ## Variables Variables originate from mathematics and are abstract concepts in computer languages that can store computation results or represent values. Variables can be accessed by their names. In Julia, variable names consist of letters, numbers, and underscores _, with the first character not being a number. Variable names are case-sensitive. Using Julia is very simpleβ€”just assign a value to a variable, as shown in the following example: ## 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 = "" # Floating-point data marks_math = 9.5 The output in interactive mode is as follows: !(#) From the example, we can see that unlike other programming languages such as C++ and Java, Julia does not require you to specify the variable typeβ€”it can automatically infer the type of the object on the right side of the equals sign. ### Naming Conventions It is recommended to follow these naming conventions: * Variable names should use lowercase. * Use underscores _ to separate words in variable names. * Type and module names should start with uppercase letters and use uppercase letters instead of underscores to separate words. * Function (`function`) and macro (`macro`) names should use lowercase without underscores. * Functions that modify their input parameters should end with `!`. These functions are sometimes called "mutating" or "in-place" functions because they modify the content of their input parameters after being called rather than just returning a value. * * * ## Comments Julia supports both single-line comments and multi-line comments. In Julia, single-line comments 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 by #= and =#, for example: ## Example #= 1. This is a single-line comment 2. This is another single-line comment =# println("Hello World!")
← Julia ArrayFunc Repeating Conic Gradient β†’