equal
deleted
inserted
replaced
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} |