python的dir、help、str用法

当你给dir()提供一个模块名字时,它返回在那个模块中定义的名字的列表。当没有为其提供参数时, 它返回当前模块中定义的名字的列表。
dir() 函数使用举例:


1

2

3

4

5

6

>>> import sys  # 获得属性列表,在这里是sys模块的属性列表

>>> dir(sys)

[‘__displayhook__‘‘__doc__‘‘__excepthook__‘‘__name__‘

‘__package__‘‘__stderr__‘‘__stdin__‘‘__stdout__‘

‘_clear_type_cache‘‘_compact_freelists‘,‘_current_frames‘

‘_getframe‘‘api_version‘‘argv‘, ...]

如果您需要快速获取任何的Python函数或语句的信息,那么您可以使用内置的“help”(帮助)功能。这是非常有用的,尤其是当使用翻译提示符时,例如,运行‘help(print)”——这将显示print函数的帮助--用于打印东西到屏幕上。

help()函数使用举例:


1

2

3

4

5

6

>>> help(print)

Help on built-in function print in module builtins:

print(...)

    print(value, ..., sep=‘ ‘, end=‘\n‘file=sys.stdout, flush=False)

...

时间: 2024-08-24 10:38:54

python的dir、help、str用法的相关文章

Python模板库Mako的用法

Mako是一个高性能的Python模板库,它的语法和API借鉴了很多其他的模板库,如Django.Jinja2等等. 基本用法 创建模板并渲染它的最基本的方法是使用 Template 类: from mako.template import Template t = Template('hello world!') print t.render() 传给 Template 的文本参数被编译为一个Python模块.模块包含一个 render_body() 函数,它产生模板的输出.调用 render

python处理word文件:win32com用法详解

目标:用python处理doc文件 方法:引入win32com模块 ************************************************************************** 一.安装 ************************************************************************** 首先要先下载安装win32com模块(起先在linux下装不成功,后在windows下面成功了...) 下载地址:http

Python错误:TypeError:'str' does not support the buffer interface

在socket套接字模块进行send和recv方法时出现这种问题,是因为Python3.x和Python2.x版本变化,In python 3, bytes strings and unicodestrings are now two different types. 相互之间需要进行转换decode()和encode(). send()需要的参数为bytes类型,因此需要对str进行encode() recv()返回的是bytes类型,因此我们需要对返回的bytes进行decode()转换为s

Python: sort,sorted,OrderedDict的用法

Python: sort,sorted,OrderedDict的用法 from http://stqdd.com/archives/427 by 莫亚菜 python对容器内数据的排序有两种,一种是容器自己的sort函数,一种是内建的sorted函数. sort函数和sorted函数唯一的不同是,sort是在容器内排序,sorted生成一个新的排好序的容器. 对于一个简单的数组 L=[5,2,3,1,4]. sort: L.sort() sorted(...)    sorted(iterabl

python中dir(),__dict__

dir()是python的一个函数, dir()函数如果接受的参数是一个类,则返回这个类所有的类变量和方法 dir()函数如果接收的参数是一个类的实例,则返回这个实例所有的实例变量,对应的类的类变量,以及方法 __dict__是类以及类的实例默认都有的属性, __dict__是一个字典,保存了两种内容,一是属性与对应的值,二是方法与对应的内存地址, 对于类来说,dict保存了类中的类变量和方法, 对于类的实例来说,dict保存了这个实例的实例变量 参考python之dir()和__dict__的

【python】sys.argv[]的用法

在学python的过程中,一直弄不明白sys.argv[]的意思,虽知道是表示命令行参数,但还是有些稀里糊涂的感觉. 今天又好好学习了一把,总算是大彻大悟了. Sys.argv[]是用来获取命令行参数的,sys.argv[0]表示代码本身文件路径,所以参数从1开始,以下两个例子说明: 1.使用sys.argv[]的一简单实例, import sys,os os.system(sys.argv[1]) 这个例子os.system接收命令行参数,运行参数指令,保存为sample1.py,命令行带参数

Python ctypes中cast/py_object用法

class ctypes.py_object Represents the C PyObject * datatype. Calling this without an argument creates a NULL PyObject * pointer. 示例: >>> dc = {'a':'aaa','b':'bbb'} >>> c = py_object(dc)>>> cpy_object({'b': 'bbb', 'a': 'aaa'})>

python re 模块 findall 函数用法简述

python re 模块 findall 函数用法简述 代码示例: 1 >>> import re 2 >>> s = "adfad asdfasdf asdfas asdfawef asd adsfas " 3 4 >>> reObj1 = re.compile('((\w+)\s+\w+)') 5 >>> reObj1.findall(s) 6 [('adfad asdfasdf', 'adfad'), ('a

java如何实现python的urllib.quote(str,safe='/')

最近需要将一些python代码转成java,遇到url编码 urllib.quote(str,safe='/') 但java中URLEncoder.encode(arg, Constant.UTF_8)会将'/'转成%2F 网上查了一下 java没见到类似的safe方式,只好自己实现一个类 package com.ppc.spider.fc.util; import java.io.ByteArrayOutputStream; import java.io.BufferedWriter; imp

python骚操作---Print函数用法

---恢复内容开始--- python骚操作---Print函数用法 在 Python 中,print 可以打印所有变量数据,包括自定义类型. 在 3.x 中是个内置函数,并且拥有更丰富的功能. 参数选项 可以用 help(print) 来查看 print 函数的参数解释. print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or