码迷,mamicode.com
首页 > 其他好文 > 详细

A string is a sequence

时间:2014-06-21 08:19:51      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   com   get   2014   

A string is a sequence of characters. You can access the characters one at a time with the bracket operator.

bubuko.com,布布扣                       

The second statement selects character number 1 from fruit and assigns it to letter. The expression in brackets is called an index. The index indicates which character in the sequence you want.

For most people the first letter of ‘banana’ is b, not a. But for computer scientists, the index is an offset from the beginning of the string, and the offset of the first letter is zero. So b is the 0th letter (‘zero-eth’) of ‘banana’, a is the 1th letter (‘one-eth’), and n is the 2th (‘two-eth’) letter.

You can use any expression, including variables and operators, as an index, but the value of the index has to be an integer. Otherwise you get error.

 

from Thinking in Python

A string is a sequence,布布扣,bubuko.com

A string is a sequence

标签:style   blog   http   com   get   2014   

原文地址:http://www.cnblogs.com/ryansunyu/p/3795193.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!