Lesson 18 of 34

Tuples: మారని Lists

7 min 20 XP

tuple అంటే ( ) తో రాసిన list లాంటిది, కానీ ఒకసారి సృష్టించాక మార్చలేం. పుట్టిన తేదీ లేదా GPS location వంటి మారని డేటాకు బాగుంటుంది.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Unpacking: tuple విలువలను ఒకే లైన్‌లో ఎన్నో variables కి ఇవ్వండి. దీంతో రెండు variables ను మార్చుకోవడం కూడా సులభం.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

ఒకే item ఉన్న tuple కి comma కావాలి: (5,). కేవలం (5) అంటే సంఖ్య 5 మాత్రమే.

Challenge

+20 XP

point = (3, 4). దాన్ని x, y గా unpack చేయండి. మొదటి లైన్‌లో x, y (space తో వేరుగా), రెండో లైన్‌లో x*x + y*y print చేయండి.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.