000001 Lecture Notes - Tuple

7 views3 pages
20 Mar 2023
Department
Course
Professor

Document Summary

Creating tuples: tuples can be created using () thistuple = ("apple", "banana", "cherry") print(thistuple) Tuple items: tuple items are ordered, unchangeable, and allow duplicate values, tuple items are indexed, the first item has index [0], the second item has index [1] etc. Creating tuples using tuple() constructor: the tuple() constructor. It is also possible to use the tuple() constructor to make a tuple: example. Using the tuple() method to make a tuple: Tuple items - data types: tuple items can be of any data type, example. String, int and boolean data types: tuple1 = ("apple", "banana", "cherry") tuple2 = (1, 5, 7, 9, 3) tuple3 = (true, false, false) How to access items from a tuple: we can access a tuple"s elements by referring to the index number. If we leave out the starting value, the range will begin from 0th index.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions