R PROGRAMMING Lecture Notes - Coding Conventions, Standard Streams

18 views3 pages

Document Summary

A tuple may be thought of as an immutable list. Tuples are constructed by placing the items inside parentheses: Tuples can be indexed and sliced in the same way as lists but, being immutable, they cannot be appended to, extended, or have elements removed from them: Typeerror: "tuple" object does not support item assignment. Although a tuple itself is immutable, it may contain references to mutable objects such as lists. >>> t = (1, ["a", "b", "d"], 0) >>> t[1][2] = "c" # ok to change the list within the tuple. An empty tuple is created with empty parentheses: t0 = (). In some circumstances, particularly for simple assignments such as those in the previous section, the parentheses around a tuple"s items are not required: This usage is an example of tuple packing. The reverse, tuple unpacking is a common way of assigning multiple variables in one line: >>> a, b, c = 97, 98, 99.

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