It is tempting to use the [] operator on the left side of an assignment, with the intention of changing a character in a string.

The ‘object’ in this case is the string and the ‘item’ is the character tried to assign. For now, an object is the same thing as a value, but we will refine that definition later. An item is one of the values in a sequence. The reason for the error is that strings are immutable, which means you can’t change an existing string. The best you can do is create a new string that is a variation on the original:

This example concatenates a new first letter onto a slice of greeting. It has no effect on the original string.

from Thinking in Python

Strings are immutable的更多相关文章

  1. Core Java Volume I — 3.6. Strings

    3.6. StringsConceptually, Java strings are sequences of Unicode characters(Java的字符串是一个Unicode序列). Fo ...

  2. Think Python - Chapter 8 - Strings

    8.1 A string is a sequenceA string is a sequence of characters. You can access the characters one at ...

  3. C# Best Practices - Handling Strings

    Features Strings Are Immutable. A String Is a Reference Type Value Type Store their data directly Ex ...

  4. 论immutable不可变性

    什么叫immutable和mutable?简单来讲,一个immutable的对象一旦被创建好,它的状态将不会改变.反过来,如果一个类的实例是immutable的,那么我们把这个类也称作immutabl ...

  5. Why are C# structs immutable?

    Compiler Error CS1612 Cannot modify the return value of 'expression' because it is not a variable cl ...

  6. Unity 最佳实践

    转帖:http://www.glenstevens.ca/unity3d-best-practices/ 另外可以参考:http://devmag.org.za/2012/07/12/50-tips- ...

  7. Java学习笔记1

    学习一个Coursera的Data-structures-optimizing-performance. Working with String in Java Flesh score Flesh s ...

  8. java标准-密码用数组比用字符串安全

    转载:http://my.oschina.net/jasonultimate/blog/166968 1) Since Strings are immutable in Java if you sto ...

  9. Microsoft Win32 to Microsoft .NET Framework API Map

    Microsoft Win32 to Microsoft .NET Framework API Map .NET Development (General) Technical Articles   ...

随机推荐

  1. HDU 4333 Contest 4

    一开始就想到了扩展KMP,因为只有扩展KMP才是处理后缀的.但忽然短路以为扩展KMP求的是最长公共后缀,囧....又浪费了很多时间,都是对这个算法练得不多 再看那个扩展KMP算法之后,就很确定要的就是 ...

  2. php给图片加入文字水印

    PHP对图片的操作用到GD库.这里我们介绍怎样给图片加入文字水印. 大致分为四步: 1.打开图片 2.操作图片 3.输出图片 4.销毁图片 以下我们上代码来详细解说每步的实现过程: <? php ...

  3. 110_leetcode_Best Time to Buy and sell Stock II

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  4. html屏蔽鼠标右键

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. Request的getParameter和getAttribute方法的差别

    HttpServletRequest.getParameter("modelName");能取到想要的modelObject吗?经过測试之后.发现是不能的. 后来想想.其它道理挺简 ...

  6. poj_3071概率dp

    确定好对手就简单了. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...

  7. [luogu P2123] 皇后游戏 解题报告(贪心)

    题目链接:https://www.luogu.org/problemnew/show/P2123 题目大意: 给定a数组和b数组,要求最小化c数组中的最大值 题解: 考虑微扰法,推一波式子先 设$x= ...

  8. avalon过滤

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    ...

  9. gui编程实战——qq聊天界面1

    public class testDemo_2 extends JFrame{ JTextArea jta=null; //多行文本框组件 JScrollPane jsp=null; //滚动文本框 ...

  10. css文字超出变省略号...

    <style>.text1 {    width:200px;    overflow:hidden;    text-overflow:ellipsis;    -o-text-over ...