-
Notifications
You must be signed in to change notification settings - Fork 0
/
datatypes.nim
66 lines (37 loc) · 1.28 KB
/
datatypes.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
let
a:int = 1
b:char = 'a' # single quote is requred
c:bool = true
d:float = 1.0
e:string = "hello" # double quotes are required
# basic data types
echo a, b, c, d, e
# to print out the type of the variable you can use .type
echo a.type, b.type, c.type, d.type, e.type
# Multiline string
# anything """ """ is a multiline string
let a2:string = """ Nim
is
Best
Langauge """
echo a2
# you can't change data types once declared
var
a5:int = 1
a5 = "nim"
echo a
# above code will throw an error becuae first we declared it as integer and then we tried to change it to string
# another example
var someInteger:int = 1
var someFloat:float = 2.3
echo someFloat + someInteger
# this will also throw an error because we are trying to add two different types
# Type Conversion: you can convert between different data types using the type conversion operator
var someInteger1:int = 1
var someFloat1:float = 2.3
echo someFloat1 + someInteger1.toFloat
# we can add .toFloat to a integer and it will convert it to an float. We can also convert a float to an integer using .toInt.
var someInteger3:int = 1
var someFloat4:float = 2.3
echo someFloat4.toInt + someInteger3
#like this