You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
doc: slight updates to noteworthy differences from Python (#38027)
* Correct a few typos
* Mention that Python comes with single-dispatch
* Correct method example for Python and Julia
* Apply suggestions from code review
Co-authored-by: Stefan Karpinski <stefan@karpinski.org>
Copy file name to clipboardExpand all lines: doc/src/manual/noteworthy-differences.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -203,7 +203,7 @@ For users coming to Julia from R, these are some noteworthy differences:
203
203
is not significant as it is in Python. Unlike Python, Julia has no `pass` keyword.
204
204
* Strings are denoted by double quotation marks (`"text"`) in Julia (with three double quotation marks for multi-line strings), whereas in Python they can be denoted either by single (`'text'`) or double quotation marks (`"text"`). Single quotation marks are used for characters in Julia (`'c'`).
205
205
* String concatenation is done with `*` in Julia, not `+` like in Python. Analogously, string repetition is done with `^`, not `*`. Implicit string concatenation of string literals like in Python (e.g. `'ab' 'cd' == 'abcd'`) is not done in Julia.
206
-
* Python Lists—flexible but slow—correspond to the Julia `Vector{Any}` type or more generally `Vector{T}` where `T` is some non-concrete element type. "Fast" arrays like Numpy arrays that store elements in-place (i.e., `dtype` is `np.float64`, `[('f1', np.uint64), ('f2', np.int32)]`, etc.) can be represented by `Array{T}` where `T` is a concrete, immutable element type. This includes built-in types like `Float64`, `Int32`, `Int64` but also more complex types like `Tuple{UInt64,Float64}` and many user-defined types as well.
206
+
* Python Lists—flexible but slow—correspond to the Julia `Vector{Any}` type or more generally `Vector{T}` where `T` is some non-concrete element type. "Fast" arrays like NumPy arrays that store elements in-place (i.e., `dtype` is `np.float64`, `[('f1', np.uint64), ('f2', np.int32)]`, etc.) can be represented by `Array{T}` where `T` is a concrete, immutable element type. This includes built-in types like `Float64`, `Int32`, `Int64` but also more complex types like `Tuple{UInt64,Float64}` and many user-defined types as well.
207
207
* In Julia, indexing of arrays, strings, etc. is 1-based not 0-based.
208
208
* Julia's slice indexing includes the last element, unlike in Python. `a[2:3]` in Julia is `a[1:3]`
209
209
in Python.
@@ -215,7 +215,7 @@ For users coming to Julia from R, these are some noteworthy differences:
215
215
* Julia has no line continuation syntax: if, at the end of a line, the input so far is a complete
216
216
expression, it is considered done; otherwise the input continues. One way to force an expression
217
217
to continue is to wrap it in parentheses.
218
-
* Julia arrays are columnmajor (Fortranordered) whereas NumPy arrays are rowmajor (C-ordered)
218
+
* Julia arrays are column-major (Fortran-ordered) whereas NumPy arrays are row-major (C-ordered)
219
219
by default. To get optimal performance when looping over arrays, the order of the loops should
220
220
be reversed in Julia relative to NumPy (see [relevant section of Performance Tips](@ref man-performance-column-major)).
221
221
* Julia's updating operators (e.g. `+=`, `-=`, ...) are *not in-place* whereas NumPy's are. This
@@ -239,12 +239,12 @@ For users coming to Julia from R, these are some noteworthy differences:
239
239
* Julia uses `nothing` of type `Nothing` to represent a null value, whereas Python uses `None` of type `NoneType`.
240
240
* In Julia, the standard operators over a matrix type are matrix operations, whereas, in Python, the standard operators are element-wise operations. When both `A` and `B` are matrices, `A * B` in Julia performs matrix multiplication, not element-wise multiplication as in Python. `A * B` in Julia is equivalent with `A @ B` in Python, whereas `A * B` in Python is equivalent with `A .* B` in Julia.
241
241
* The adjoint operator `'` in Julia returns an adjoint of a vector (a lazy representation of row vector), whereas the transpose operator `.T` over a vector in Python returns the original vector (non-op).
242
-
* In Julia, a function may contain multiple concrete implementations (called *Methods*), selected via multiple dispatch, whereas functions in Pythonhave a single implementation (no polymorphism).
242
+
* In Julia, a function may contain multiple concrete implementations (called *methods*), which are selected via multiple dispatch based on the types of all arguments to the call, as compared to functions in Python, which have a single implementation and no polymorphism (as opposed to Python method calls which use a different syntax and allows dispatch on the receiver of the method).
243
243
* There are no classes in Julia. Instead they are structures (mutable or immutable), containing data but no methods.
244
-
* Calling a method of a class in Python (`a = MyClass(x), x.func(y)`) corresponds to a function call in Julia, e.g. `a = MyStruct(x), func(x::MyStruct, y)`. In general, multiple dispatch is more flexible and powerful than the Python class system.
244
+
* Calling a method of a class instance in Python (`x = MyClass(*args); x.f(y)`) corresponds to a function call in Julia, e.g. `x = MyType(args...); f(x, y)`. In general, multiple dispatch is more flexible and powerful than the Python class system.
245
245
* Julia structures may have exactly one abstract supertype, whereas Python classes can inherit from one or more (abstract or concrete) superclasses.
246
-
* The logical Julia program structure (Packages and Modules) is independent of the file strucutre (`include` for additional files), whereas the Python code structure is defined by directories (Packages) and files (Modules).
247
-
* The ternary operator `x > 0 ? 1 : -1` in Julia corresponds to conditional expression in Python `1 if x > 0 else -1`.
246
+
* The logical Julia program structure (Packages and Modules) is independent of the file structure (`include` for additional files), whereas the Python code structure is defined by directories (Packages) and files (Modules).
247
+
* The ternary operator `x > 0 ? 1 : -1` in Julia corresponds to a conditional expression in Python `1 if x > 0 else -1`.
248
248
* In Julia the `@` symbol refers to a macro, whereas in Python it refers to a decorator.
249
249
* Exception handling in Julia is done using `try` — `catch` — `finally`, instead of `try` — `except` — `finally`. In contrast to Python, it is not recommended to use exception handling as part of the normal workflow in Julia due to performance reasons.
250
250
* In Julia loops are fast, there is no need to write "vectorized" code for performance reasons.
0 commit comments