码迷,mamicode.com
首页 > 编程语言 > 详细

Learn Python 004: string slicing

时间:2017-07-10 23:37:28      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:bsp   use   cto   tput   sep   oct   rip   step   sof   

monthsofyear = ‘JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember‘
monthof1 = monthsofyear[0:7:1]
print(monthof1)
monthof2 = monthsofyear[7:15:1]
print(monthof2)
monthof3 = monthsofyear[15:20:1]
print(monthof3)
gibberish1 = monthsofyear[::2]
print(gibberish1)
gibberish2 = monthsofyear[7::2]
print(gibberish2)
gibberish3 = monthsofyear[::-1]
print(gibberish3)
monthof4 = monthsofyear[monthsofyear.index(‘June‘):monthsofyear.index(‘July‘)]
print(monthof4)
monthof5 = monthsofyear[monthsofyear.index(‘Jul‘):monthsofyear.index(‘Aug‘)]
print(monthof5)
monthof11 = monthsofyear[monthsofyear.index(‘No‘):monthsofyear.index(‘De‘)]
print(monthof11)
monthof12 = monthsofyear[monthsofyear.index(‘De‘):]
print(monthof12)

# email slicer
# step 1: get user email address
email = input(‘Please enter your email address: ‘).strip()
# step 2: slice out user name
username = email[:email.index(‘@‘)]
# print(username)
# step 3: slice domain name
domain = email[email.index(‘@‘) + 1 :]
# print(domain)
# step 4: format message
output = ‘Your username is "{}" and your domain name is "{}".‘.format(username, domain)
# step 5: display output message
print(output)

 

Learn Python 004: string slicing

标签:bsp   use   cto   tput   sep   oct   rip   step   sof   

原文地址:http://www.cnblogs.com/mxyzptlk/p/7148025.html

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