package main
import "fmt"
func printInteger (aNumber int) {
fmt.Printf("The number is %d.", aNumber) // Print to console
}
// This is where the app starts executing
func main() {
var number int = 42 // Declare and initialize the variable
printInteger(number) // Call a function
}
const printInteger = (aNumber: number): void => {
console.log(`The number is ${aNumber}`) //Print to console
}
let number = 42 // Declare and initialize the variable
printInteger(number) // Call a function
void printInteger (int aNumber) {
print("The number is $aNumber.")
}
// This is where the app starts executing
void main() {
var number = 42; // Declare and initialize a variable
printInteger(number); // Call a function
}
def printInteger(aNumber: int) -> void:
print(f"The number is {aNumber}") // Print to console
number: int = 42
printIteger(number)
function printInteger(aNumber::Int64)
println("The number is $aNumber") # Print to console
end
number = 42 # Declare and initialize a variable
printInteger(number) # Call a function
Object
or dynamic
for variable not restricted to type. In Go, this can be done with the interface
.var num int = 8
var ToBe bool = false
var (
MaxInt uint64 = 1<<64 - 1
z complex128 = cmplx.Sqrt(-5 + 12i) // import "math/cmplx"
)
// int int8 int16 int32(rune) int64
// uint uint8(byte) int16 int32 int64
aNum := 23 // inferred, only works within main()
// string bool float32 float64 complex64 complex128
var values [4]int = {1, 3, 4, 6}
var inert []map[string]string = []map[string]string{
{"percent": "21", "gas": "oxygen"},
{"percent": "78", "gas": "nitrogen"},
}
let a = "Hello World" // string
let b = 5.69 // number
let c = true, // boolean
gas = null // null
gases: string[] = ["helium", "oxygen", "hydrogen"] // TS
let inert:Record<string, string>[] = [
{ "percent": "21", "gas": "oxygen"},
{ "percent": "78", "gas": "nitrogen"}]
int numOne = 1;
double numTwo = 3.14159;
String str = "Educative";
bool val = true;
List<String> gases = ["helium", "oxygen", "hydrogen"]; // use can still use var
var flybyObjects = ['Jupiter', 'Saturn', 'Uranus', 'Neptune'];
var image = {
'tags': ['saturn'],
'url': '//path/to/saturn.jpg'
};
List<Map<string, string>> inert = [
{ "percent": "21", "gas": "oxygen"},
{ "percent": "78", "gas": "nitrogen"}
];
num: int = 2
pi: float = 3.14
name: str = "Hello world"
found: bool = True
gases: list[str] = ["helium", "oxygen", "hydrogen"]
inert: list[dict[str, str]] = [
{ "percent": "21", "gas": "oxygen"},
{ "percent": "78", "gas": "nitrogen"}]
# type above is for python 3.9+
# for earlier versions use
from typing import List, Dict
x = 41 # Int
y = 'e' # Char
y = "e" # String
a = (1, 2, 3) # Tuple
local x::Int8 # in a local declaration
x::Int8 = 10 # as the left-hand side of an assignment
mydict = Dict{Char, Int64}('a'=>1, 'b'=>2, 'c'=>3) # Dict
inert = Dict{String, String}[
Dict("percent" => "21", "gas" => "oxygen"),
Dict("percent" => "78", "gas" => "nitrogen")] # List of Dict
a = Set([1,2,2,3,4])