首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python中利用py帮助命令扩展开发知识面

python中利用py帮助命令扩展开发知识面

作者头像
刘金玉编程
发布2019-08-20 13:07:57
4570
发布2019-08-20 13:07:57
举报
文章被收录于专栏:编程创造城市编程创造城市
知识回顾:

上一节主要学习了%取余数,举例如下:

5%3=2

利用这个取余的方法,我们可以计算几天后是星期几的问题?

计算公式:(今天是星期几+几天后)%7


本节知识视频教程

一、回到python REPL

python REPL简称python控制台。

往往企业中的生产环境比较简单,但是需要我们可能去解决一些bug,需要现场调试,此时,现场开发,可能用到帮助来提示我们一些函数的用法。

二、如何利用帮助命令解决问题?

1、利用dir()函数来获取当前环境下面有哪些模块?

方法如下:

>>> dir()

['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']

>>> import math

>>> dir()

['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'math']

由此,我们观察出,导入的模块也会被纳入进去。

那么,我们如何利用帮助命令解决问题呢?

2、利用help命令来获取模块下面的所有函数

help(模块名称):返回所有的函数的详细解释。

help(模块名称.函数名称):返回某个函数的详细解释。

使用方法举例:

>>> help(math)

Help on built-in module math:

NAME

math

DESCRIPTION

This module is always available. It provides access to the

mathematical functions defined by the C standard.

FUNCTIONS

acos(x, /)

Return the arc cosine (measured in radians) of x.

acosh(x, /)

Return the inverse hyperbolic cosine of x.

asin(x, /)

Return the arc sine (measured in radians) of x.

asinh(x, /)

Return the inverse hyperbolic sine of x.

atan(x, /)

Return the arc tangent (measured in radians) of x.

atan2(y, x, /)

Return the arc tangent (measured in radians) of y/x.

Unlike atan(y/x), the signs of both x and y are considered.

-- More --

那么,如果我是使用dir函数会怎样呢?

dir(参数):参数是模块名称

返回这个模块下的所有的模块名称。

使用举例:

>>> dir(math)

['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']

三、Python中如何调用cmd命令?

1、导入os模块

import os

2、查看函数

dir(os)

3、找到执行cmd命令的函数system

help(os.system)

4、调用cmd命令的函数

os.system(“cls”) 执行cls来清空当前窗体。

四、总结强调

1、掌握help函数看帮助详细。

2、掌握dir函数看当前环境下有哪些变量、模块等。

3、掌握通过导入os模块来调用cmd命令。

相关文章:

  1. python中类的构造方法
  2. Python中类的接口
  3. python中利用API文档开发与学习
  4. python中类和对象
  5. python中函数递归VS循环
  6. python中函数的可变参数
  7. python中自定义序列的实现
  8. python第一个程序,定位在小学数学还是幼儿园?
  9. python输入与输出涨姿势
  10. python中整型与浮点型的数值转换
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-08-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 编程创造城市 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档