最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

slice operation of consequence in python

常识 admin 21浏览 0评论

slice operation of consequence in python

the  slice operation consequence is easy.

the prototype of the function  is str[start:end:step] .

then let's see the  following examples:

>>>str1='abcde'

>>>str1[1:3]

'bc'

>>>str1[:]    #default start is 0 and default end is (len(str)-1)

'abcde'

>>>str1[1:4:1]

'bcd'

>>>str1[0:4:2]

'ace'

>>>str1[-4]

'b'

>>>str1[-4:-1]

'bcd'

>>>str1[-4:-1:1]

'bcd'

>>>str1[-4:-1:-1]

'dcb'

>>>str1[::2]    #default start is 0 and default end is (len(str)-1)

'aec'



slice operation of consequence in python

the  slice operation consequence is easy.

the prototype of the function  is str[start:end:step] .

then let's see the  following examples:

>>>str1='abcde'

>>>str1[1:3]

'bc'

>>>str1[:]    #default start is 0 and default end is (len(str)-1)

'abcde'

>>>str1[1:4:1]

'bcd'

>>>str1[0:4:2]

'ace'

>>>str1[-4]

'b'

>>>str1[-4:-1]

'bcd'

>>>str1[-4:-1:1]

'bcd'

>>>str1[-4:-1:-1]

'dcb'

>>>str1[::2]    #default start is 0 and default end is (len(str)-1)

'aec'



发布评论

评论列表 (0)

  1. 暂无评论