- Mastering Python Scripting for System Administrators
- Ganesh Sanjiv Naik
- 64字
- 2021-07-02 14:00:24
Accessing values in tuples
To access values in a tuple, use the square brackets for slicing along with the index or indices to obtain the value available at that index or indices, as shown in the following example:
#!/usr/bin/python3
cities = ('Mumbai', 'Bangalore', 'Chennai', 'Pune')
numbers = (1, 2, 3, 4, 5, 6, 7)
print (cities[3])
print (numbers[1:6])
Output:
Pune
(2, 3, 4, 5)
推薦閱讀
- Oracle 11g從入門到精通(第2版) (軟件開發(fā)視頻大講堂)
- Python數(shù)據(jù)分析入門與實(shí)戰(zhàn)
- The Modern C++ Challenge
- ASP.NET Core 2 and Vue.js
- PhpStorm Cookbook
- 3D少兒游戲編程(原書第2版)
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- Hands-On Reinforcement Learning with Python
- Go并發(fā)編程實(shí)戰(zhàn)
- Protocol-Oriented Programming with Swift
- Spring MVC+MyBatis開發(fā)從入門到項(xiàng)目實(shí)踐(超值版)
- NGUI for Unity
- 從零開始學(xué)算法:基于Python
- CryENGINE Game Programming with C++,C#,and Lua
- 大話C語言