Julia – 117 – differenze rispetto altri linguaggi – Python

Continuo da qui, copio qui.

Salto la sezione di R, linguaggio a me sconosciuto 😊

Per quanto riguarda Python occorre tener presente le differenze tra le versioni 2 e 3. Alle volte capitano inconvenienti. E la 2.x è ancora usata.

Julia requires end to end a block. Unlike Python, Julia has no pass keyword.

In Julia, indexing of arrays, strings, etc. is 1-based not 0-based.

Julia’s slice indexing includes the last element, unlike in Python. a[2:3] in Julia is a[1:3] in Python.

Julia does not support negative indexes. In particular, the last element of a list or array is indexed with end in Julia, not -1 as in Python.

Julia’s for, if, while, etc. blocks are terminated by the end keyword. Indentation level is not significant as it is in Python.

Julia has no line continuation syntax: if, at the end of a line, the input so far is a complete expression, it is considered done; otherwise the input continues. One way to force an expression to continue is to wrap it in parentheses.

Julia arrays are column major (Fortran ordered) whereas NumPy arrays are row major (C-ordered) by default. To get optimal performance when looping over arrays, the order of the loops should be reversed in Julia relative to NumPy.

Julia’s updating operators (e.g. +=, -=, ...) are not in-place whereas NumPy’s are. This means A = ones(4); B = A; B += 3 doesn’t change values in A, it rather rebinds the name B to the result of the right- hand side B = B + 3, which is a new array. Use B[:] += 3, explicit loops, or InplaceOps.jl.

Julia evaluates default values of function arguments every time the method is invoked, unlike in Python where the default values are evaluated only once when the function is defined. For example, the function f(x=rand()) = x returns a new random number every time it is invoked without argument. On the other hand, the function g(x=[1,2]) = push!(x,3) returns [1,2,3] every time it is called as g().

In Julia % is the remainder operator, whereas in Python it is the modulus.

🤩

 

Posta un commento o usa questo indirizzo per il trackback.

Trackback

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.

%d blogger hanno fatto clic su Mi Piace per questo: