- Hands-On Penetration Testing with Python
- Furqan Khan
- 179字
- 2021-07-02 14:13:51
Tuples in Python
A Python tuple is very similar to a Python list. The difference is that it's a read-only structure, so once it is declared, no modification can be made to the elements of the tuple. Python tuples can be used as follows:

In the preceding code, we can see that we can access tuples in the same way as we can access lists, but when we try to change any element of the tuple, it throws us an exception as a tuple is a read-only structure. If we perform the operations that we performed on lists, we will see that they work in exactly the same way as tuples:

If a tuple has only one element in it, it has to be declared with a trailing comma. If we do not add that comma while declaring it, it will be interpreted as a numeric or string data type, depending on the elements of the tuple. The following example explains this better:

A tuple can be converted into a list and can then be operated on as follows:

- Python for Secret Agents:Volume II
- SQL Server 2012數據庫技術及應用(微課版·第5版)
- HTML5 移動Web開發從入門到精通(微課精編版)
- 程序員考試案例梳理、真題透解與強化訓練
- Java Web開發詳解
- R語言:邁向大數據之路(加強版)
- Learning Unreal Engine Game Development
- Python Linux系統管理與自動化運維
- 企業級Java現代化:寫給開發者的云原生簡明指南
- WCF全面解析
- Python程序設計:基礎與實踐
- 趣學數據結構
- ASP.NET jQuery Cookbook(Second Edition)
- MySQL從入門到精通
- Swift 2 Blueprints