- Mastering Python Scripting for System Administrators
- Ganesh Sanjiv Naik
- 155字
- 2021-07-02 14:00:20
Strings
Like numbers, strings are also one of the data structures in Python. Python can manipulate strings. Strings can be expressed as follows:
- Enclosed in single quotes ('...')
- Enclosed in double quotes ("...")
See the following example:
>>> 'Hello Python'
'Hello Python'
>>> "Hello Python"
'Hello Python'
A string is a set of characters. We can access the characters one at a time, as follows:
>>> city = 'delhi'
>>> letter = city[1]
>>> letter = city[-3]
In the second statement, we are selecting the character number 1 from city and assigning it to letter. The number in those square brackets is an index. The index indicates which character you want to access. It starts from 0. So, in the preceding example, when you will execute letter = city[1], you will get the following output:
city d e l h i
index 0 1 2 3 4
-5 -4 -3 -2 -1
Output:
e
l
推薦閱讀
- 小程序實戰視頻課:微信小程序開發全案精講
- Ceph Cookbook
- 深入淺出Electron:原理、工程與實踐
- Mastering RStudio:Develop,Communicate,and Collaborate with R
- Apache Spark 2.x for Java Developers
- SQL Server與JSP動態網站開發
- 硬件產品設計與開發:從原型到交付
- OpenCV with Python Blueprints
- RocketMQ實戰與原理解析
- 深度學習程序設計實戰
- Java從入門到精通(視頻實戰版)
- Building Clouds with Windows Azure Pack
- Linux Networking Cookbook
- PHP典型模塊與項目實戰大全
- 計算機軟件項目實訓指導