Skip to Content
可编程网络自动化
book

可编程网络自动化

by Jason Edelman, Scott S. Lowe, Matt Oswalt
January 2023
Intermediate to advanced
458 pages
14h 16m
Chinese
Posts & Telecom Press
Content preview from 可编程网络自动化
在网络场景中学习
Python
89
称,如下例所示。
>>>
for
my_attribute, my_value,
in
device.items():
...
print
(my_attribute + ': ' + my_value)
...
os : 12.1
hostname : router1
vendor : juniper
cpu : 5%
memory : 10%
>>>
我们现在已经介绍了
Python
的主要数据类型。你应该很好地理解了字符串、数字、布尔值、
列表以及字典的用法。接下来将继续简要地介绍两种比较高级的数据类型:集合和元组。
4.3.6
 学习
Python
集合与元组
这两种数据类型并不是非要在介绍
Python
的时候涉及,但正如本章在开始时说过的那样,
这么做是出于完整性的考虑。下面“登场”的数据类型是
set
tuple
如果你理解了列表,就能理解集合。集合就是元素的列表,但集合中的特定元素只能有一
个,额外的元素无法被索引(或者说无法像列表那样通过索引值访问)。
可以看到集合形似列表,但是出现在
set()
内。
>>> vendors = set(['arista', 'cisco', 'arista', 'cisco', 'juniper', 'cisco'])
>>>
上例中创建的集合包含了多个相同的元素。在使用
count()
统计列表中的特定厂商出现了
多少次的时候用到过类似的例子。但如果只想知道有多少家厂商以及这些厂商都是哪些的
话,该怎么办?可以使用集合。
>>> vendors ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python和NLTK实现自然语言处理

Python和NLTK实现自然语言处理

Posts & Telecom Press, Nitin Hardeniya
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
弱监督学习实用指南

弱监督学习实用指南

Wee Hyong Tok, Amit Bahree, Senja Filipi
Python实用技能学习指南

Python实用技能学习指南

Posts & Telecom Press, Robert Smallshire, Austin Bingham

Publisher Resources

ISBN: 9787115606181