Introduction
In this lesson, we’ll discuss the difference between constants and variables and go over some general rules for naming and declaring them. We also emphasize the importance of type inference in automatically determining the data type of a constant or variable.
Some general rules
No semicolons
It is recommended that each individual statement be placed on a separate line. In that case, semicolons (;) are not needed to indicate the end of the statement.
However, semicolons (;) are necessary if you want to write multiple statements on a single line.
Comment lines
// This is a single comment line
/* This long comment spans
two lines */
Comments can help make parts of the code easier to understand. A single comment line is denoted by //. Multiple comment lines must be enclosed between /* and */
Constants and Variables
Names
You can choose your own meaningful names for constants and variables. However, names cannot start with a digit and cannot contain special characters such as spaces, arrows, or math symbols. The Swift coding guidelines recommend using camelCase for naming conventions (the first letter of the name is lowercase, and the following words in the name always start with a capital letter).
The Swift language is case-sensitive. This means that it distinguishes between uppercase and lowercase letters. The variables lastName, LastName and lastname are three different variables in Swift.
Swift is a case-sensitive language!
Constants
A constant is assigned a value that cannot be changed. A constant must always be declared before it can be used. A constant can be defined with the let keyword:

In the first line, you define a constant firstName of type String and assign the value “John” to it.
In the second line, you define a constant lastName and assign the value “Walters” to it. The constant lastName will be a String since you assign the String literal (“Walters”) to it.
In most cases, Swift can infer the type of the assigned value. The inferred type is therefore the type of the constant.
Please note that it is not possible to change the values of constants. If you try to do so, you will receive an error message.
Variables
As the name suggests, the value assigned to a variable can still be changed. A variable must also be declared before it can be used. A variable can be declared with the var keyword:

In the first line, you define the variable totalInvoice of type Double and assign the value 4578.25.
In the second line, you define the variable productPrice and assign the value 45.67 to it. The variable productPrice will be of type Double , since the number 45.67 is considered a Double.
In most cases, you do not need to explicitly specify the type of a constant or variable in Swift. The ability to deduce the data type of another constant, variable, expression, etc.is called type inference.
Swift data types
The following table summarizes the main Swift data types:
| Data type | Description |
|---|---|
| Int | Integer: used to store whole numbers. |
| Double | Used to store 64-bit decimal numbers. |
| Float | Used to store 32-bit decimal numbers. |
| Bool | Boolean: used to store a boolean value (true or false). |
| Character | Used to store a single character. |
| String | Used to store a string of characters (text). |
A Swift data type always starts with a capital letter!