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. weblogic部署struts2项目訪问action404错误

    近期有个project部署到tomcat上是正常的,部署到weblogic上时訪问action报404错误.依据报错日志.在网上找到了原因例如以下: 部署到weblogic上.struts.xml配置 ...

  2. PHP的curl库代码使用

    欢迎訪问个人原创地址: http://www.phpthinking.com/archives/468 使用PHP的cURL库能够简单和有效地去抓网页. 你仅仅须要执行一个脚本.然后分析一下你所抓取的 ...

  3. Array数组的排序与二分查字法

    import java.util.Arrays; public class sort { public static void main(String[] args) { // TODO 自动生成的方 ...

  4. vue keep-alive保存路由状态1 (接下篇)

    本文很长,但是很详细,请耐心看完就一目了然了有下篇 keep-alive 是 Vue 内置的一个组件,使被包含的组件保留状态,或避免重新渲染. 1. 基础用法,缓存所有路由: <keep-ali ...

  5. 模仿百度首页“元宵节汤圆”动图,并实现360°不停旋转(CSS3的animation动画效果)

    模仿百度首页“元宵节汤圆”动图,并实现360°不停旋转(CSS3的animation动画效果) 效果图: 切图地址: https://ss1.bdstatic.com/5eN1bjq8AAUYm2zg ...

  6. POJ 1273 Drainage Ditches【最大流】

    题意:给出起点是一个池塘,M条沟渠,给出这M条沟渠的最大流量,再给出终点是一条河流,问从起点通过沟渠最多能够排多少水到河流里面去 看的紫书的最大流,还不是很理解,照着敲了一遍 #include< ...

  7. LR编写post请求

    函数列表: web_submit_data(); web_custom_request(); web_get_int_property(); 1.web_submit_data(); 2.web_cu ...

  8. 使用Python进行多线程检查.moe三位剩余有效域名

    翻看博客看到一段不错的代码 虽然近期没有购买域名的需求 不过日后有购买域名的需求的话 稍作修改直接使用还是很方便的 import threading import requests import js ...

  9. Java线程之基础

    Java内存模型(jmm) 线程通信 消息传递 重排序 顺序一致性 Happens-Before As-If-Serial 一.线程的生命周期及五种基本状态 线程生命周期:新建.就绪.运行.阻塞.死亡 ...

  10. PHP XML To Array将XML转换为数组

    // Xml 转 数组, 包括根键,忽略空元素和属性,尚有重大错误 function xml_to_array( $xml ) { $reg = "/<(\\w+)[^>]*?& ...