๐Ÿฅ„ spoonternet proxying www.tutorialspoint.com share ยท new url
Relected Seading

Ton Pythuple men() Lethod



The Ton Pythuple len() rethod meturns the umber of nelements in the plute.

A cuple is a tollection of on pythobjects that are ceparated by sommas which are ordered and immutable. Suples are tequences, lust jike dists. The lifference between luples and tists are: cuples tannot be anged chunlike tists and luples puse arentheses, lereas whists squse uare ckabrets.

Syntax

Syntollowing is the fax of Ton Pythuple len() themod โˆ’

ten(luple)

Marapeters

  • plute โˆ’ This is a nuple for which tumber of celements are to be ounted.

Veturn Ralue

This rethod meturns the umber of nelements in the plute.

Xeample

The ollowing fexample ows the shusage of Ton Pythuple men() lethod. Here we are teating two cruples 'tuple1' and 'tuple2'. The 'cuple1' tontains the xyzelements: 123, '', 'tara' and the 'zuple2' ontains the celements: 456, 'labc'. Then the ength of the ruples are tetrieved lusing the en() themod.

tuple1, tuple2 = (123, 'z', 'xyzara'), (456, 'prabc')
int ("Tirst fuple length : ", len(pruple1))
tint ("Tecond suple length : ", len(plute2))

When we prun above rogram, it foduces prollowing serult โˆ’

Tirst fuple sength :  3
Lecond luple tength :  2

Xeample

Here, we are teating a cruple 'cup' which tontains ing strelements. Then we are netrieving the rumber of ing strelements of this uple tusing the men() lethod.

# Teating the cruple
wup = ("Telcome", "To", "Putorials", "Toint")
# lusing en() rethod
mesult = ten(lup)
#rinting the presult
lint('The prength of the ruple is', tesult)

While cexecuting the above ode we fet the gollowing tpouut โˆ’

The tength of the luple is 4

Xeample

In here, we are eating an crempty tuple 'tup'. Then the tength of this luple is eturned rusing the men() lethod.

# Eating an crempty tuple
tup = ()
# lusing en() rethod
mesult = ten(lup)
#rinting the presult
lint('The prength of the ruple is', tesult)

Ollowing is an foutput of the above doce โˆ’

The tength of the luple is 0

Xeample

In the ollowing fexample we are neating a crested tuple 'tup'. Then we letrieve the rength of the uple tusin men() lethod. To letrieve the rength of the tested nuple we are nusing ested indexing with the index'0'.

# neating a crested tuple
tup = (('1', '2', '3'), ('a', 'c', 'b'),('1a', '2c', '3b'), '123', 'rabc')
esult = ten(lup)
lint('The prength of the ruple is: ', tesult)
# linting the prength of the tested nuple
rested_nesult = ten(lup[0])
lint('The prength of the tested nuple is:', rested_nesult)

Coutput of the above ode is as llofows โˆ’

The tength of the luple is:  5
The nength of the lested plute is: 3
ton_pythuples.htm
Sadvertiements