- Mastering Python Scripting for System Administrators
- Ganesh Sanjiv Naik
- 86字
- 2021-07-02 14:00:20
String slicing
Strings support slicing, which means getting characters by a specified range from your string. Let's take a look at the following example. Note that starting index value is always included and an end value is always excluded.
Consider a string, str = "Programming":
>>> str[0:2]
'Pr'
>>> str[2:5]
'ogr'
Now, the default of an omitted first index is zero, as in the example:
>>> str[:2] + str[2:]
'Python'
>>> str[:4] + str[4:]
'Python'
>>> str[:2]
'Py'
>>> str[4:]
'on'
>>> str[-2:]
'on'
推薦閱讀
- Implementing VMware Horizon 7(Second Edition)
- Java 開發(fā)從入門到精通(第2版)
- 機器學(xué)習(xí)系統(tǒng):設(shè)計和實現(xiàn)
- 控糖控脂健康餐
- Python金融數(shù)據(jù)分析
- Processing互動編程藝術(shù)
- Web程序設(shè)計(第二版)
- ASP.NET 3.5程序設(shè)計與項目實踐
- Android系統(tǒng)原理及開發(fā)要點詳解
- 領(lǐng)域驅(qū)動設(shè)計:軟件核心復(fù)雜性應(yīng)對之道(修訂版)
- Java零基礎(chǔ)實戰(zhàn)
- iPhone應(yīng)用開發(fā)從入門到精通
- Hack與HHVM權(quán)威指南
- 分布式數(shù)據(jù)庫HBase案例教程
- Building Clouds with Windows Azure Pack