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调用Orator ORM进行数据库操作

《Python调用OratorORM进行数据库操作》OratorORM是一个功能丰富且灵活的PythonORM库,旨在简化数据库操作,它支持多种数据库并提供了简洁且直观的API,下面我们就... 目录Orator ORM 主要特点安装使用示例总结Orator ORM 是一个功能丰富且灵活的 python O

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

python使用fastapi实现多语言国际化的操作指南

《python使用fastapi实现多语言国际化的操作指南》本文介绍了使用Python和FastAPI实现多语言国际化的操作指南,包括多语言架构技术栈、翻译管理、前端本地化、语言切换机制以及常见陷阱和... 目录多语言国际化实现指南项目多语言架构技术栈目录结构翻译工作流1. 翻译数据存储2. 翻译生成脚本

如何通过Python实现一个消息队列

《如何通过Python实现一个消息队列》这篇文章主要为大家详细介绍了如何通过Python实现一个简单的消息队列,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录如何通过 python 实现消息队列如何把 http 请求放在队列中执行1. 使用 queue.Queue 和 reque

Python如何实现PDF隐私信息检测

《Python如何实现PDF隐私信息检测》随着越来越多的个人信息以电子形式存储和传输,确保这些信息的安全至关重要,本文将介绍如何使用Python检测PDF文件中的隐私信息,需要的可以参考下... 目录项目背景技术栈代码解析功能说明运行结php果在当今,数据隐私保护变得尤为重要。随着越来越多的个人信息以电子形

使用Python快速实现链接转word文档

《使用Python快速实现链接转word文档》这篇文章主要为大家详细介绍了如何使用Python快速实现链接转word文档功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 演示代码展示from newspaper import Articlefrom docx import

Python Jupyter Notebook导包报错问题及解决

《PythonJupyterNotebook导包报错问题及解决》在conda环境中安装包后,JupyterNotebook导入时出现ImportError,可能是由于包版本不对应或版本太高,解决方... 目录问题解决方法重新安装Jupyter NoteBook 更改Kernel总结问题在conda上安装了

Python如何计算两个不同类型列表的相似度

《Python如何计算两个不同类型列表的相似度》在编程中,经常需要比较两个列表的相似度,尤其是当这两个列表包含不同类型的元素时,下面小编就来讲讲如何使用Python计算两个不同类型列表的相似度吧... 目录摘要引言数字类型相似度欧几里得距离曼哈顿距离字符串类型相似度Levenshtein距离Jaccard相

Python安装时常见报错以及解决方案

《Python安装时常见报错以及解决方案》:本文主要介绍在安装Python、配置环境变量、使用pip以及运行Python脚本时常见的错误及其解决方案,文中介绍的非常详细,需要的朋友可以参考下... 目录一、安装 python 时常见报错及解决方案(一)安装包下载失败(二)权限不足二、配置环境变量时常见报错及

Python中顺序结构和循环结构示例代码

《Python中顺序结构和循环结构示例代码》:本文主要介绍Python中的条件语句和循环语句,条件语句用于根据条件执行不同的代码块,循环语句用于重复执行一段代码,文章还详细说明了range函数的使... 目录一、条件语句(1)条件语句的定义(2)条件语句的语法(a)单分支 if(b)双分支 if-else(