Are strings mutable in python?
Anonymous
>>> a = 'str1' >>> a[3] = '2' Traceback (most recent call last): File "", line 1, in TypeError: 'str' object does not support item assignment >>> But let's take a look at example: >>> a = 'str1' >>> b = 'str2' >>> a = b >>> print a str2 >>> List is mutable: >>> a = ['s','t','r',1] >>> print a ['s', 't', 'r', 1] >>> a[3] = 2 >>> print a ['s', 't', 'r', 2] >>>
Check out your Company Bowl for anonymous work chats.