Example on ranges
This commit is contained in:
parent
432516feba
commit
2eeece02e7
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue