/* Go is statically typed. A type defines the set of values and the set of operations that can take place on those valies. */ // Elementary or primitive types: int, float, bool, string. // Structured or composite types: struct, array, slice, map, channel. // Interfaces describe the behavior of a type. /* We can create a user defined data type. It's also possible to have an alias for data types. An alias for int for example could be declared like so: */ type IZ int // Then, to declar an integer variable, we have to use an alias like so: var a IZ = 5 // To define more tha one type we can do it like so: type ( IZ int FZ float32 STR string ) /* We can convert a value into another type of value through type-casting. However, Go does not allow implicit conversion, which means that Go never does such a conversion by itself. The conversion must be done explicitly as valueOfTypeB = typeB(valuePFTypeA). For example: */ package main import "fmt" func main(){ var number float32 = 5.2 // Declared a floating point variable fmt.Println(number) // Printing the value of variable fmt.Println(int(number)) // Printing the type-casted result
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter