Example on ranges

This commit is contained in:
Federico Ceratto 2015-07-14 15:01:50 +01:00
parent 432516feba
commit 2eeece02e7
1 changed files with 13 additions and 1 deletions

View File

@ -128,6 +128,18 @@ So, when using inheritance, be sure to inherit using refs, unless you know what
## From Python to Nim
### Ranges
The syntax for ranges is different. a[x:y] becomes a[x..<y]
Also, a[x..y] is inclusive.
``` Nim
let a = @[1,2,3,4]
a[0..0] # returns @[1]
a[0..1] # returns @[1, 2]
a[0..<2] # returns @[1, 2]
a[0..3] # returns @[1, 2, 3, 4]
```
### Python strings
Use double quotes: "foo" or """foo""", not 'foo'
@ -136,7 +148,7 @@ Strings are always unicode. Remember to use runes() to iterate over unicode char
``` Nim
var a = "hello"
echo a[0..1] # returns "he": ranges are inclusive!
echo a[0..1] # returns "he": ranges are inclusive! See the "Ranges" paragraph
```
### Python tuples