Local variables¶
Local variables are declared when you first assign them a value.
The name always starts with a lowercase Unicode letter. It can also start with an underscore, which usually indicates that the value is unused. Names starting with two underscores are reserved by the compiler.
The following characters are Unicode alphanumeric or underscores.
As a typical convention, upper-case letters are avoided and names are written in snake_case.
name = "Crystal"
age = 1
Their type is inferred from their usage, not only from their initializer. In general, they are just value holders associated with the type that the programmer expects them to have according to their location and usage on the program.
For example, reassigning a variable with a different expression makes it have that expression’s type:
flower = "Tulip"
# At this point 'flower' is a String
flower = 1
# At this point 'flower' is an Int32