- Mastering Python Scripting for System Administrators
- Ganesh Sanjiv Naik
- 79字
- 2021-07-02 14:00:22
Strings are immutable
Strings are immutable, meaning we can't change the values. Refer to the given example:
>>> welcome = 'Hello, John!'
>>> welcome[0] = 'Y'
TypeError: 'str' object does not support item assignment
As the strings are immutable; we cannot change an existing string. But we can create a new string that will be different from the original:
>>> str1 = 'Hello John'
>>> new_str = 'Welcome' + str1[5:]
>>> print(str1)
Hello John
>>> print(new_str)
Welcome John
>>>
推薦閱讀
- Web應用系統(tǒng)開發(fā)實踐(C#)
- jQuery Mobile Web Development Essentials(Third Edition)
- C程序設計簡明教程(第二版)
- Python自然語言處理實戰(zhàn):核心技術與算法
- 青少年美育趣味課堂:XMind思維導圖制作
- Scratch 3.0少兒編程與邏輯思維訓練
- Full-Stack Vue.js 2 and Laravel 5
- Hands-On Swift 5 Microservices Development
- Scala Reactive Programming
- Django 3.0應用開發(fā)詳解
- Django實戰(zhàn):Python Web典型模塊與項目開發(fā)
- 現(xiàn)代C:概念剖析和編程實踐
- 青少年學Python(第2冊)
- Java RESTful Web Service實戰(zhàn)
- 從零開始學算法:基于Python