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

相关文章

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Python使用python-can实现合并BLF文件

《Python使用python-can实现合并BLF文件》python-can库是Python生态中专注于CAN总线通信与数据处理的强大工具,本文将使用python-can为BLF文件合并提供高效灵活... 目录一、python-can 库:CAN 数据处理的利器二、BLF 文件合并核心代码解析1. 基础合

Python使用OpenCV实现获取视频时长的小工具

《Python使用OpenCV实现获取视频时长的小工具》在处理视频数据时,获取视频的时长是一项常见且基础的需求,本文将详细介绍如何使用Python和OpenCV获取视频时长,并对每一行代码进行深入解析... 目录一、代码实现二、代码解析1. 导入 OpenCV 库2. 定义获取视频时长的函数3. 打开视频文

Python中你不知道的gzip高级用法分享

《Python中你不知道的gzip高级用法分享》在当今大数据时代,数据存储和传输成本已成为每个开发者必须考虑的问题,Python内置的gzip模块提供了一种简单高效的解决方案,下面小编就来和大家详细讲... 目录前言:为什么数据压缩如此重要1. gzip 模块基础介绍2. 基本压缩与解压缩操作2.1 压缩文

Python设置Cookie永不超时的详细指南

《Python设置Cookie永不超时的详细指南》Cookie是一种存储在用户浏览器中的小型数据片段,用于记录用户的登录状态、偏好设置等信息,下面小编就来和大家详细讲讲Python如何设置Cookie... 目录一、Cookie的作用与重要性二、Cookie过期的原因三、实现Cookie永不超时的方法(一)

Python内置函数之classmethod函数使用详解

《Python内置函数之classmethod函数使用详解》:本文主要介绍Python内置函数之classmethod函数使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录1. 类方法定义与基本语法2. 类方法 vs 实例方法 vs 静态方法3. 核心特性与用法(1编程客

Python函数作用域示例详解

《Python函数作用域示例详解》本文介绍了Python中的LEGB作用域规则,详细解析了变量查找的四个层级,通过具体代码示例,展示了各层级的变量访问规则和特性,对python函数作用域相关知识感兴趣... 目录一、LEGB 规则二、作用域实例2.1 局部作用域(Local)2.2 闭包作用域(Enclos

Python实现对阿里云OSS对象存储的操作详解

《Python实现对阿里云OSS对象存储的操作详解》这篇文章主要为大家详细介绍了Python实现对阿里云OSS对象存储的操作相关知识,包括连接,上传,下载,列举等功能,感兴趣的小伙伴可以了解下... 目录一、直接使用代码二、详细使用1. 环境准备2. 初始化配置3. bucket配置创建4. 文件上传到os

使用Python实现可恢复式多线程下载器

《使用Python实现可恢复式多线程下载器》在数字时代,大文件下载已成为日常操作,本文将手把手教你用Python打造专业级下载器,实现断点续传,多线程加速,速度限制等功能,感兴趣的小伙伴可以了解下... 目录一、智能续传:从崩溃边缘抢救进度二、多线程加速:榨干网络带宽三、速度控制:做网络的好邻居四、终端交互

Python中注释使用方法举例详解

《Python中注释使用方法举例详解》在Python编程语言中注释是必不可少的一部分,它有助于提高代码的可读性和维护性,:本文主要介绍Python中注释使用方法的相关资料,需要的朋友可以参考下... 目录一、前言二、什么是注释?示例:三、单行注释语法:以 China编程# 开头,后面的内容为注释内容示例:示例:四