julia 编程语言
Julia中的变量 (Variables in Julia)
Just like other programming languages, in Julia variables are the name of memory blocks that are associated (or bound) to a value. It is useful when a value to be stored or to be accessed in/from memory locations.
就像其他编程语言一样,在Julia中,变量是与值关联(或绑定)的内存块的名称。 在存储位置或从存储位置访问或存储值时很有用。
声明变量的规则 (Rules to declare a variable)
A variable name must be started with:
变量名称必须以以下内容开头:
- a letter (A to Z/a to z), or
- an underscore (_), or
- a subset of Unicode code points greater than 00A0
A variable name must not contain any special character (exception some of the character in special cases).
变量名不得包含任何特殊字符(特殊情况下某些字符除外)。
Digits (0-9) can be used in the variable name (not as a starting letter)
可以在变量名称中使用数字(0-9)(不能用作起始字母)
变量命名约定 (Variable naming conventions)
For a better programming style in Julia, we should remember the following points,
为了使用Julia更好的编程风格,我们应该记住以下几点,
Variable names should be in lowercase
变量名应小写
Instead of using space as a word separator in variable names, we should use underscore (_).
不要使用空格作为变量名称中的单词分隔符,而应使用下划线(_)。
Types names and Modules names should be started with a capital letter (uppercase), if the variable name is long (used multiple words) then for word separation, we should not use underscore (-), instead of using underscore (_) use the first letter as capital (uppercase) of each word.
类型名称和模块名称应以大写字母开头(大写),如果变量名称很长(使用多个单词),则为了进行单词分隔,我们不应使用下划线(-),而应使用下划线(_)使用第一个字母作为每个单词的大写(大写)。
Functions and macros names should be in lowercase without word separation.
函数和宏的名称应为小写字母,且不要单词分隔。
声明变量并赋值 (Declaring a variable and Assigning values)
Since Julia does not support data type with the global variables, the variable automatically detects its type based on the given values.
由于Julia不支持全局变量的数据类型,因此变量会根据给定的值自动检测其类型。
Example:
例:
# variables
a = 10
b = 10.23
c = 'c'
d = "Hello"
# printing the values
println("Initial values...")
println("a: ", a)
println("b: ", b)
println("c: ", c)
println("d: ", d)
# updating the values
a = a + 10
b = b + 12
c = 'x'
d = "world!"
# printing the values
println("After updating...")
println("a: ", a)
println("b: ", b)
println("c: ", c)
println("d: ", d)
Output
输出量
Initial values...
a: 10
b: 10.23
c: c
d: Hello
After updating...
a: 20
b: 22.23
c: x
d: world!
Reference: https://docs.julialang.org
参考: https : //docs.julialang.org
翻译自: https://www.includehelp.com/julia/variables.aspx
julia 编程语言