Skip to content

Instantly share code, notes, and snippets.

@mzechmeister
Last active May 2, 2023 06:52
Show Gist options
  • Save mzechmeister/c4eadc732faa3a99b60de4ec9f7e3b7a to your computer and use it in GitHub Desktop.
Save mzechmeister/c4eadc732faa3a99b60de4ec9f7e3b7a to your computer and use it in GitHub Desktop.
python vs julia

Expericence with julia (coming from python)

python julia comment
print(1, 2) πŸ€¦β€β™‚οΈ println(1, " ", 2) why I need to type ln?
slicing πŸ‘ a[::2] πŸ€¦β€β™‚οΈ a[1:2:end] too verbose (start/stop must be given)
πŸ€¦β€β™‚οΈ sin.(a) .- 1 silly dot
func def πŸ‘ f(x) = 2*x
complex numbers πŸ‘ 1j 1im
πŸ‘ 2x πŸ€¦β€β™‚οΈ 0x syntax: invalid numeric constant "0x"
πŸ€¦β€β™‚οΈ [1, 2.+0im] syntax: invalid syntax "2.+"; add space(s) to clarify
πŸ€¦β€β™‚οΈ [1, 2. +0im] syntax: missing separator in array expression
πŸ€¦β€β™‚οΈ [1] * (0:0.1:1).step too strict MethodError: no method matching *(::Vector{Int64}, ::Base.TwicePrecision{Float64})

Uh, note the difference: 1 ./ x vs 1. / x.

  • 1+[1, 2]: MethodError: no method matching +(::Int64, ::Vector{Int64})
  • 1.+[1, 2]: syntax: invalid syntax "1.+"; add space(s) to clarify
  • 1 .+[1, 2]: works πŸ€¦β€β™‚οΈ
  • 1. .+[1, 2]: convert to double
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment