- 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'
推薦閱讀
- LabVIEW2018中文版 虛擬儀器程序設計自學手冊
- Practical Data Science Cookbook(Second Edition)
- Raspberry Pi for Secret Agents(Third Edition)
- Spring Boot+Spring Cloud+Vue+Element項目實戰:手把手教你開發權限管理系統
- JavaScript前端開發與實例教程(微課視頻版)
- HTML5+CSS3+JavaScript Web開發案例教程(在線實訓版)
- Getting Started with Gulp
- 微服務從小白到專家:Spring Cloud和Kubernetes實戰
- 第一行代碼 C語言(視頻講解版)
- Python機器學習:預測分析核心算法
- Learning Hadoop 2
- Cocos2d-x Game Development Blueprints
- 動手打造深度學習框架
- 深入理解BootLoader
- JSP程序設計與案例實戰(慕課版)