Henrique Andrade
Henrique Andrade

Reputation: 991

Julia equivalent of Python's "help()"

In python to get the documentation of a function, we can type (for example) help(len).

How to do the same to get a function's documentation in Julia?

Upvotes: 9

Views: 4771

Answers (1)

carstenbauer
carstenbauer

Reputation: 10127

In Julia you can use a question mark followed by a function name, i.e. ?functionname, to get information about a function.

If you are using the REPL, the question mark will switch your julia> prompt to a help?> prompt - similar to how ] triggers the pkg> REPL mode. Check out the documentation for more information.

In Jupyter notebooks (IJulia) you just type ?println and there is no visible REPL mode change.

Example:

help?> println # I typed ?println
search: println printstyled print sprint isprint

  println([io::IO], xs...)

  Print (using print) xs followed by a newline. If io is not supplied, prints to stdout.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> println("Hello, world")
  Hello, world

  julia> io = IOBuffer();

  julia> println(io, "Hello, world")

  julia> String(take!(io))
  "Hello, world\n"

Note that this approach isn't restricted to functions. It works for all objects that have some docstrings attached to them:

help?> Sys.CPU_THREADS # docstring of a constant
  Sys.CPU_THREADS

  The number of logical CPU cores available in the system, i.e. the number of threads that the CPU can run concurrently. Note that this is not necessarily the number of CPU cores, for example, in the presence of hyper-threading (https://en.wikipedia.org/wiki/Hyper-threading).

  See Hwloc.jl or CpuId.jl for extended information, including number of physical cores.

Upvotes: 11

Related Questions