day2/cheatsheet2.tex
changeset 330 46533051b9d3
parent 329 0a6ab1d81491
equal deleted inserted replaced
329:0a6ab1d81491 330:46533051b9d3
   191 \section{Tuples}
   191 \section{Tuples}
   192 Tuples are sequences just like Lists, but they are \textbf{immutable}, or items/elements cannot be changed in any way.
   192 Tuples are sequences just like Lists, but they are \textbf{immutable}, or items/elements cannot be changed in any way.
   193 \begin{lstlisting}
   193 \begin{lstlisting}
   194 In []: t = (1, 2, 3, 4, 5, 6, 7, 8) 
   194 In []: t = (1, 2, 3, 4, 5, 6, 7, 8) 
   195 \end{lstlisting}
   195 \end{lstlisting}
   196 \textbf{Note:} For tupels we use parantheses in place of square brackets, rest is same as lists.
   196 \textbf{Note:} For tuples we use parentheses in place of square brackets, rest is same as lists.
   197 \begin{lstlisting}
   197 \begin{lstlisting}
   198 In []: t[0] + t[3] + t[-1] # elements are accessed via indices
   198 In []: t[0] + t[3] + t[-1] # elements are accessed via indices
   199 Out[]: 13
   199 Out[]: 13
   200 In []: t[4] = 7 # ERROR: tuples are immutable
   200 In []: t[4] = 7 # ERROR: tuples are immutable
   201 \end{lstlisting}
   201 \end{lstlisting}