Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the basis and common operations of tuples in Python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge about "how to understand the basics and common operations of tuples in Python". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

directory

1. Introduction to tuples

2. access tuple

3. Modify tuples (which cannot be modified)

4. Tuples have built-in functions such as count, index

5. type conversion

1. Convert tuples to lists

2. Convert tuples to collections

1. Introduction to tuples

Python tuples are similar to lists, except that the elements of tuples cannot be modified.

Tuples use parentheses, lists use square brackets.

Tuples are easy to create by adding elements in parentheses and separating them with commas.

Format of tuple:

tup=('a ',' b','c',' d') 2. Access Tuples

Tuples can be accessed using subscript indices, which start at 0, to access values in tuples

For example:

tup=('a','b','c','d')print(tup[0])print(tup[1])print(tup[2])print(tup[3])

It can also be accessed by looping

use a for loop

For example:

tup1=('a','b','c','d')for i in tup1: print(i)

Use the while loop

tup1 =('a ',' b','c',' d') i=0# len is the length of computation tup1 while i

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report