day2/cheatsheet1.tex
changeset 327 c78cad28c2f7
parent 321 8bf99f747817
child 329 0a6ab1d81491
equal deleted inserted replaced
326:f57f42861770 327:c78cad28c2f7
    72 In []: print w[1]
    72 In []: print w[1]
    73 Out[]: e
    73 Out[]: e
    74 In []: print w[-1] #last character of string
    74 In []: print w[-1] #last character of string
    75 Out[]: o
    75 Out[]: o
    76   \end{lstlisting}
    76   \end{lstlisting}
    77 \textbf{Note:} For a string variable, individual elements can be accessed using indices.
    77 \textbf{Note:} For a string variable, individual elements can be accessed using indices.\\
       
    78 \textbf{Note:} All slicing and striding operations works with strings as well.
    78   \begin{lstlisting}
    79   \begin{lstlisting}
    79 In []: len(w) #function to calculate length of string
    80 In []: len(w) #function to calculate length of string
    80 Out[]: 5
    81 Out[]: 5
    81 In []: w[0] = 'H' # ERROR: Strings are immutable 
    82 In []: w[0] = 'H' # ERROR: Strings are immutable 
    82   \end{lstlisting}
    83   \end{lstlisting}