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

What is the definition of tuple in python development

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

Share

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

This article focuses on "what is the definition of tuples in python development". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the definition of tuple in python development"?

Tuple is a basic concept in a relational database. A relationship is a table. Each row in the table (that is, each record in the database) is a tuple, and each column is an attribute. In a two-dimensional table, tuples are also called rows.

Tuple: tuples, tuples that gather multiple objects together and cannot be modified. Use parentheses "()" to bring in lines to find them.

Application scenario: use some data as a whole and cannot be modified

1. Description

The Python tuple cmp () function is used to compare two tuple elements.

2. Grammar

The syntax of the cmp () method:

Cmp (tuple1, tuple2)

3. Parameters

Tuple1-the tuple of the comparison.

Tuple2-another tuple to compare.

4. Return value

If the compared element is of the same type, compare its value and return the result.

If two elements are not of the same type, check to see if they are numbers.

If it is a number, perform the necessary numeric cast, and then compare.

If one side's element is a number, the other side's element is "large" (the number is "smallest").

Otherwise, compare by the alphabetical order of the type names.

If one list reaches the end first, another longer list is "larger".

If we exhaust the elements of the two lists and all the elements are equal, the result is a draw, that is, a 0 is returned.

5. Python data editing

Tuples are very similar to lists, except that tuples are as immutable as strings, that is, you cannot modify tuples. Tuples are defined by items separated by commas in parentheses. Tuples are usually used to enable statements or user-defined functions to safely adopt a set of values, that is, the values of the tuples used do not change.

6. The written form and specification of tuples in Python:

Tuplename= (tupleitem1,tupleitem2,tupleitem3,tupleitem4)

Tuplename=tupleitem1,tupleitem2,tupleitem3,tupleitem4

Note: tuples are defined by commas, not parentheses.

Zoo = ('wolf',' elephant', 'penguin')

Print 'Number of animals in the zoo is', len (zoo)

New_zoo = ('monkey',' dolphin', zoo)

Print 'Number of animals in the new zoo is', len (new_zoo)

Print 'All animals in new zoo are', new_zoo

Print 'Animals brought from old zoo are', new_zoo [2]

Print 'Last animal brought from old zoo is', new_zoo [2] [2]

An empty tuple consists of a pair of empty parentheses, such as myempty = (). However, a tuple containing a single element must be followed by a comma after the first (only) item so that Python can distinguish between a tuple and a parenthesized object in an expression.

At this point, I believe you have a deeper understanding of "what is the definition of tuples in python development". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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