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
81
>>> 'network' == 'network'
True
>>>
>>> 'network' == 'no_network'
False
>>>
简要地了解布尔对象、运算符和表达式之后,再来看一看如何使用
Python
列表。
4.3.4
 学习使用
Python
列表
在前面讲述字符串内建方法
join()
split()
时,简单介绍过列表。现在来详细地说一说。
列表是类型为
list
的对象,究其根本而言,就是有序的对象序列。这里再次引用先前介绍
join()
方法时用到的例子,快速回顾一下如何创建列表。这些例子全都是字符串列表,但
很快你就会看到,也可以创建任何其他数据类型的列表。
>>> hostnames = ['r1', 'r2', 'r3', 'r4', 'r5']
>>> commands = ['config t', 'interface Ethernet1/1', 'shutdown']
>>>
下面的例子就展示了一个不同数据类型的对象列表。
>>> new_list = ['router1', False, 5]
>>>
>>>
print
(new_list)
['router1', False, 5]
>>>
现在你已经明白列表就是出现在方括号内的有序的对象序列。在使用列表时,最常碰到的
一项任务就是访问列表元素。
让我们来创建一个新的接口列表,演示如何打印出单个列表元素。
>>> interfaces = ['Eth1/1', 'Eth1/2', 'Eth1/3', ...
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