A quick and dirty syntax translation guide to ease the transition between Python and Julia.
- Arrays in Julia are indexed starting from 1.
- In Julia class (i.e. types) don't own methods. Methods are implementations of generic functions and are invoked in a "static style", i.e. instead of Python's str1.rstrip(), we will have rstrip( str1 ), instead of file1.close(), close( file1 ).
| Python | Julia |
|---|---|
| True | true |
| False | false |
| None | nothing |
| type( obj ) | typeof( obj ) |
| {} | Dict{KeyType,ValueType}() |
| elif | elseif |
| Python | Julia |
|---|---|
| str1 + str2 | string( str1, str2 ) |
| len( str1 ) | length( str1 ) |
| str1.rstrip() | rstrip( str1 ) |
| Python | Julia |
|---|---|
| m = re.match( r"(\d+):(\d+)", mystr ) | m = match( r"(\d+):(\d+)", mystr ) |
m is not None |
m != nothing |
| arr = m.groups() | arr = m.captures |
| Python | Julia |
|---|---|
| f = open( "file.txt" ) | f = open( "file.txt") |
| for line in f | for line in eachline( f ) |
| f.close() | close( f ) |
Now there is a
startswithfunction inBase.