- 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:

- C語(yǔ)言程序設(shè)計(jì)案例教程
- 新編Visual Basic程序設(shè)計(jì)上機(jī)實(shí)驗(yàn)教程
- Visual FoxPro程序設(shè)計(jì)教程
- 微服務(wù)與事件驅(qū)動(dòng)架構(gòu)
- SQL for Data Analytics
- Clojure for Domain:specific Languages
- Bootstrap 4:Responsive Web Design
- Scala程序員面試算法寶典
- Scala for Machine Learning(Second Edition)
- ASP.NET程序開發(fā)范例寶典
- Swift 4從零到精通iOS開發(fā)
- Python 3 Object:oriented Programming(Second Edition)
- 算法秘籍
- Joomla!Search Engine Optimization
- HikariCP數(shù)據(jù)庫(kù)連接池實(shí)戰(zhàn)