栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Jupyter notebook基础命令

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Jupyter notebook基础命令

在这里不叙述如何配置Jupyter Notebook,使用环境为Macos + python 3.8

运行一个单元格快捷键为:Shift + Enter(运行一个单元格并选择下一个)

内省:

一个变量名 的前/后 使用 ? 可以显示有关该对象的概要信息

an_apple?

Type:        int
String form: 1
Docstring:  
int([x]) -> integer
int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments
are given.  If x is a number, return x.__int__().  For floating point
numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in the
given base.  The literal can be preceded by '+' or '-' and be surrounded
by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0)
4

你也可以自定义函数,写好文档字符串
双问号 ?? 显示源代码,这里不单独显示

def add_number(a, b):
    """
    add two numbers
    Returns
    --------
    the_sum
    """
    return a + b
add_number?

Signature: add_number(a, b)
Docstring:
add two numbers
Returns
--------
the_sum
File:      /var/folders/9l/fdqtn9lj3mqd1mr7rsbr_qlc0000gn/T/ipykernel_49969/3572536628.py
Type:      function

终极用途是:把 ? 和 * 结合在一起使用,会显示所有匹配通配符表达式的命名,例如:查np里包含load的函数名列表

import numpy as np
np.*load*?
np.__loader__
np.load
np.loads
np.loadtxt
补全键:

Tab

%run命令:

可以使用%run来运行你已经写好了的.py脚本文件

# 注意这里传入的都是字符串
%run test.py 1 2
# test.py
import sys

def add2num(a, b):
    return a + b

ans = sys.argv
print(add2num(int(ans[1]), int(ans[2])))
中断执行:

Ctrl + C:引起KeyBoardInterrupt

IPython快捷键:

Ctrl + C:引起KeyBoardInterrupt
Ctrl + A:光标移到本行开头
Ctrl + E:光标移到本行末尾
Ctrl + K:删除光标后,本行所有内容
Ctrl + U:删除当前行

对象类型:

看对象a的种类:type(a)
询问,a是某种对象吗:isinstance(a, int),isinstance(a, (int, float)) 返回Bool类型

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/740140.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号