Julia相当于Python的“ help()”

时间:2019-06-11 08:40:10

标签: julia

在python中,以获取函数的文档,我们可以键入(例如)help(len)

如何在Julia中获取功能文档?

1 个答案:

答案 0 :(得分:4)

在Julia中,您可以使用问号后跟一个函数名称(即?functionname)来获取有关函数的信息。

如果您使用的是the REPL,问号会将您的julia>提示切换为help?>提示-类似于]触发pkg> REPL的方式模式。请查看documentation,以了解更多信息。

在Jupyter笔记本(IJulia)中,您只需键入?println,并且没有可见的REPL模式更改。

示例:

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"

请注意,这种方法不限于功能。它适用于所有附加了文档字符串的对象:

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.