Lesson 18 of 34

Tuples: न बदलणाऱ्या Lists

7 min 20 XP

Tuple म्हणजे ( ) ने लिहिलेली list सारखीच, पण तयार झाल्यावर बदलता येत नाही. जन्मतारीख किंवा GPS location सारख्या न बदलणाऱ्या data साठी उत्तम.

Example: edit me and press Run

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

Unpacking: एका ओळीत tuple च्या values अनेक variables ना द्या. यामुळे दोन variables swap करणेही सोपे होते.

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 ने वेगळे) print करा, मग दुसऱ्या ओळीत x*x + y*y.

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