python help() 帮助文档 哪里不会查哪里

2024-05-26 16:08
文章标签 python 文档 不会 帮助 help

本文主要是介绍python help() 帮助文档 哪里不会查哪里,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

help

在python中遇到不会的方法怎么办,用help查一下用法。
用法help()放入函数名,不需要加括号。首先来个套娃,查询一下help函数的用法。

help(help)

class _Helper(builtins.object)
| Define the builtin ‘help’.
|
| This is a wrapper around pydoc.help that provides a helpful message
| when ‘help’ is typed at the Python interactive prompt.
|
| Calling help() at the Python prompt starts an interactive help session.
| Calling help(thing) prints help for the python object ‘thing’.

print

然后查询一下print()方法的用法。

help(print)

print(…)
print(value, …, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.

a = 1
b = [2,3,4]
c = "miao"
print(a, b, c)
print(a, b, c, sep=", ")
print(a, b, c, sep="\n")
print(a, end="--")
print(b, end="--")
print(c, end="--")

1 [2, 3, 4] miao
1, [2, 3, 4], miao
1
[2, 3, 4]
miao
1–[2, 3, 4]–miao–

sys

help('sys')

或者

import sys
help(sys)

也可以

import sys
help(sys.path)

查询某个具体方法

help(sys.path.append)

append(object, /) method of builtins.list instance
Append object to the end of the list.

基础数据类型

int型数据

number = 666
help(number)

bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| ‘0b100101’
| >>> (37).bit_length()
| 6

number = 666
print(bin(number))
print(number.bit_length())

0b1010011010
10
数组类型

array = [1,2,3]
help(array)   

数组的一些常用方法如下

append(self, object, /)
| Append object to the end of the list.
|
| clear(self, /)
| Remove all items from list.
|
| copy(self, /)
| Return a shallow copy of the list.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| extend(self, iterable, /)
| Extend list by appending elements from the iterable.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| insert(self, index, object, /)
| Insert object before index.
|
| pop(self, index=-1, /)
| Remove and return item at index (default last).
|
| Raises IndexError if list is empty or index is out of range.
|
| remove(self, value, /)
| Remove first occurrence of value.
|
| Raises ValueError if the value is not present.
|
| reverse(self, /)
| Reverse IN PLACE.
|
| sort(self, /, *, key=None, reverse=False)
| Sort the list in ascending order and return None.

help(array.append)

append(object, /) method of builtins.list instance
Append object to the end of the list.

string类型数据

string="miao"
print(type(string))
help(string)

<class ‘str’>
No Python documentation found for ‘miao’.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.

help(str)

str的常用方法如下

startswith(…)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|

time

import time
help(time.time)

time(…)
time() -> floating point number
Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides them.

format

help(format)

format(value, format_spec=’’, /)
Return value.format(format_spec)

format_spec defaults to the empty string.
See the Format Specification Mini-Language section of help('FORMATTING') for
details.

关于format详情可以参见print(help(‘FORMATTING’))。

help('FORMATTING')

Format String Syntax


The “str.format()” method and the “Formatter” class share the same
syntax for format strings (although in the case of “Formatter”,
subclasses can define their own format string syntax). The syntax is
related to that of formatted string literals, but there are
differences.
Format strings contain “replacement fields” surrounded by curly braces
“{}”. Anything that is not contained in braces is considered literal
text, which is copied unchanged to the output. If you need to include
a brace character in the literal text, it can be escaped by doubling:
“{{” and “}}”.

可以直接拉到例子部分。

Format examples
===============
This section contains examples of the “str.format()” syntax and
comparison with the old “%”-formatting.
In most of the cases the syntax is similar to the old “%”-formatting,
with the addition of the “{}” and with “:” used instead of “%”. For
example, “’%03.2f’” can be translated to “’{:03.2f}’”.
The new format syntax also supports new and different options, shown
in the following examples.

```python
print('{:.2f}'.format(3453.2398473))

3453.24

torch.ones

help(torch.ones)

ones(…)
ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a tensor filled with the scalar value 1, with the shape defined
by the variable argument :attr:size.
Args:
size (int…): a sequence of integers defining the shape of the output tensor.
Can be a variable number of arguments or a collection like a list or tuple.
Keyword arguments:
out (Tensor, optional): the output tensor.
dtype (:class:torch.dtype, optional): the desired data type of returned tensor.
Default: if None, uses a global default (see :func:torch.set_default_tensor_type).
layout (:class:torch.layout, optional): the desired layout of returned Tensor.
Default: torch.strided.
device (:class:torch.device, optional): the desired device of returned tensor.
Default: if None, uses the current device for the default tensor type
(see :func:torch.set_default_tensor_type). :attr:device will be the CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: False.
Example::

torch.ones(2, 3)
tensor([[ 1., 1., 1.],
[ 1., 1., 1.]])

torch.ones(5)
tensor([ 1., 1., 1., 1., 1.])

np.rand.normal

features
print(help(features))

| size(…)
| size() -> torch.Size
|
| Returns the size of the :attr:self tensor. The returned value is a subclass of
| :class:tuple.
|
| Example::
|
| >>> torch.empty(3, 4, 5).size()
| torch.Size([3, 4, 5])

  • help is all you need.
    在这里插入图片描述

这篇关于python help() 帮助文档 哪里不会查哪里的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/1004947

相关文章

python常见环境管理工具超全解析

《python常见环境管理工具超全解析》在Python开发中,管理多个项目及其依赖项通常是一个挑战,下面:本文主要介绍python常见环境管理工具的相关资料,文中通过代码介绍的非常详细,需要的朋友... 目录1. conda2. pip3. uvuv 工具自动创建和管理环境的特点4. setup.py5.

Python常用命令提示符使用方法详解

《Python常用命令提示符使用方法详解》在学习python的过程中,我们需要用到命令提示符(CMD)进行环境的配置,:本文主要介绍Python常用命令提示符使用方法的相关资料,文中通过代码介绍的... 目录一、python环境基础命令【Windows】1、检查Python是否安装2、 查看Python的安

Python UV安装、升级、卸载详细步骤记录

《PythonUV安装、升级、卸载详细步骤记录》:本文主要介绍PythonUV安装、升级、卸载的详细步骤,uv是Astral推出的下一代Python包与项目管理器,主打单一可执行文件、极致性能... 目录安装检查升级设置自动补全卸载UV 命令总结 官方文档详见:https://docs.astral.sh/

Python并行处理实战之如何使用ProcessPoolExecutor加速计算

《Python并行处理实战之如何使用ProcessPoolExecutor加速计算》Python提供了多种并行处理的方式,其中concurrent.futures模块的ProcessPoolExecu... 目录简介完整代码示例代码解释1. 导入必要的模块2. 定义处理函数3. 主函数4. 生成数字列表5.

Python中help()和dir()函数的使用

《Python中help()和dir()函数的使用》我们经常需要查看某个对象(如模块、类、函数等)的属性和方法,Python提供了两个内置函数help()和dir(),它们可以帮助我们快速了解代... 目录1. 引言2. help() 函数2.1 作用2.2 使用方法2.3 示例(1) 查看内置函数的帮助(

Python虚拟环境与Conda使用指南分享

《Python虚拟环境与Conda使用指南分享》:本文主要介绍Python虚拟环境与Conda使用指南,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、python 虚拟环境概述1.1 什么是虚拟环境1.2 为什么需要虚拟环境二、Python 内置的虚拟环境工具

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

Python pip下载包及所有依赖到指定文件夹的步骤说明

《Pythonpip下载包及所有依赖到指定文件夹的步骤说明》为了方便开发和部署,我们常常需要将Python项目所依赖的第三方包导出到本地文件夹中,:本文主要介绍Pythonpip下载包及所有依... 目录步骤说明命令格式示例参数说明离线安装方法注意事项总结要使用pip下载包及其所有依赖到指定文件夹,请按照以

Python实现精准提取 PDF中的文本,表格与图片

《Python实现精准提取PDF中的文本,表格与图片》在实际的系统开发中,处理PDF文件不仅限于读取整页文本,还有提取文档中的表格数据,图片或特定区域的内容,下面我们来看看如何使用Python实... 目录安装 python 库提取 PDF 文本内容:获取整页文本与指定区域内容获取页面上的所有文本内容获取

基于Python实现一个Windows Tree命令工具

《基于Python实现一个WindowsTree命令工具》今天想要在Windows平台的CMD命令终端窗口中使用像Linux下的tree命令,打印一下目录结构层级树,然而还真有tree命令,但是发现... 目录引言实现代码使用说明可用选项示例用法功能特点添加到环境变量方法一:创建批处理文件并添加到PATH1