Learn_Python_关键字_标识符_None_range04

关键字

关键字就是Python语言定义的,具有特殊用途的单词。

通过内置函数help(),keywords 查看所有关键字

help()
Welcome to Python 3.7's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at https://docs.python.org/3.7/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> keywords

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not                 

详细Python内置函数:https://www.runoob.com/python/python-built-in-functions.html

标识符

所谓标识符,就是给程序中的变量,函数,方法,类等命名的名字

标识符的命名规则(必须这样命名):

(1)区分大小写

(2)不能是关键字

(3)不能以数字开头

(4)不能包含空格,制表符,数学符号,中划线,箭头等



标识符的命名规范(推荐这样命名):

(1)“见名知意”,由一个或多个有意义的单词组合而成。

计算机科学中最难的两件事是命名和缓和失效。

(2)所有单词全部小写,单词之间用下划线进行分割。

例如:student_name,return_result.

# 标识符区分大小写
i = 3
I = 5
print(i)
print(I)
3
5

什么是对象None

对象None用于表示数据值不存在。

对象None是占据一定的内存空间的,它并不意味着“空”或“没有定义”,

也就是说,None是“something”,而不是“nothing”。

对象None的使用场景

对象None经常用于变量的初始化,或者将变量重置为“数据值不存在”状态

a = None
print(a)
None
b = 18
print(b)
b = None
print(b)
18
None

range是一种序列类型,range类型用于表示不可变的整数序列

可以调用内置函数range(类range的构造方法)创建range类型的对象,有三种调用方式:

1.range(stop)

2.range(start,stop)

3.range(start,stop,step)

其中,整数序列的起始值的默认值是0,可以使用参数start指定。

可以使用参数stop指定整数序列的结束值,

整数序列的步长的默认值是1,可以使用参数step进行指定。



内置函数range的返回值是一个迭代器对象,为了清楚地表示返回的迭代器对象所表示的整数序列,可以将其转换成列表。



range类型的优点在于:不管range对象表示的整数序列有多长,所有range对象占用的内存空间都是相同的,

因为仅仅需要存储start,stop和step。只有当用到range对象时,才会去计算序列中的相关元素。

print(range(5))
print(list(range(5)))
print(list(range(0,5,1)))
range(0, 5)
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4]
print(list(range(1,5)))
print(list(range(1,5,1)))
print(list(range(0,20,4)))
print(list(range(0,-20,-4)))
[1, 2, 3, 4]
[1, 2, 3, 4]
[0, 4, 8, 12, 16]
[0, -4, -8, -12, -16]

可以使用运算符in(not in)检查range对象表示的整数序列中是否存在(不存在)指定的整数。

print(3 in range(5))
True
print(8 not in range(5))
True

学习参考:

  1. 图解Python: http://e-learning.51cto.com/course/12803
  2. Python菜鸟教程:https://www.runoob.com/python/python-tutorial.html
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
modAL是一个用于主动学习的Python框架。主动学习是一种机器学习方法,其中算法可以选择最有用的样本进行标记,以提高模型的准确性。modAL提供了一组工具,使用户能够轻松地实现主动学习算法。以下是modAL的一些特点和使用方法: 1. modAL支持多种主动学习策略,包括不确定性采样、查询-by-committee、信息熵等。 2. modAL提供了一组易于使用的API,使用户能够轻松地实现主动学习算法。 3. modAL支持多种机器学习框架,包括scikit-learn、Keras和PyTorch等。 4. modAL提供了一组可视化工具,使用户能够更好地理解主动学习算法的工作原理。 以下是一个使用modAL进行主动学习的示例代码: ```python from modAL.models import ActiveLearner from modAL.uncertainty import uncertainty_sampling from sklearn.datasets import load_iris from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split # 加载据集 iris = load_iris() X_raw = iris['data'] y_raw = iris['target'] # 划分训练集和测试集 X_train, X_test, y_train, y_test = train_test_split(X_raw, y_raw, test_size=0.3, random_state=0) # 初始化主动学习器 learner = ActiveLearner( estimator=RandomForestClassifier(), query_strategy=uncertainty_sampling, X_training=X_train, y_training=y_train ) # 开始主动学习 N_QUERIES = 20 for idx in range(N_QUERIES): query_idx, query_instance = learner.query(X_test) learner.teach(X_test[query_idx].reshape(1, -1), y_test[query_idx].reshape(-1, )) test_accuracy = learner.score(X_test, y_test) print('Accuracy after query {n}: {acc:0.4f}'.format(n=idx + 1, acc=test_accuracy)) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZPILOTE

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值