zoukankan      html  css  js  c++  java
  • 2019年12月29日 MRKJ page125 实战+字符串

    checi=['T40','T298','Z158']
    dizhi=['cj','bj','sh']
    atime=['2h','1h','3h']
    c1=dict(zip(checi,dizhi))
    print(c1)
    a1=dict(zip(checi,atime))
    print(a1)
    print('checi','	','dizhi','	','atime')
    for i in checi:
        print(i,'	',c1[i],'	',a1[i])#注意	的用法和效果
    cc=input('you buy the checi:')
    print('sorry' if cc not in checi else '')
    people=input('your name:')
    print('you buy zhe'+c1[cc]+','+people+' please take the ticket')

     》》》》

    {'T40': 'cj', 'T298': 'bj', 'Z158': 'sh'}
    {'T40': '2h', 'T298': '1h', 'Z158': '3h'}
    checi dizhi atime
    T40 cj 2h
    T298 bj 1h
    Z158 sh 3h
    you buy the checi:T40

    your name:SXJ
    you buy zhecj,SXJ please take the ticket

    字符串也可以同list一样做切片

    s='人生苦短,我用python!'
    print(s[0:4])
    print(s[3])
    print(s[3:])
    print(s[:8])
    print(s[::-1])#倒序

    》》》

    人生苦短

    短,我用python!
    人生苦短,我用p
    !nohtyp用我,短苦生人

    s='人 生 苦 短,我用python!'
    a=s.split(',')
    b=s.split()
    c=s.split(' ',2)
    print(a,'
    ',b,'
    ',c)
    
    d='*'.join(s) #s是可迭代对象,所以可以是list,可以是元祖,也可以是str
    print(d)
    
    name=['a','b','c']
    e='@'.join(name)
    print(e) #注意第一个没有@的
    print('@'+e)

    》》》

    ['人 生 苦 短,我用python!']
    ['人', '生', '苦', '短,我用python!']
    ['人', '生', '苦 短,我用python!']
    人* *生* *苦* *短*,*我*用*p*y*t*h*o*n*!
    a@b@c
    @a@b@c

    s='人 生 苦 短,我用python!'
    f=s.count(' ')
    g=s.find(' ')#返回首次出现的位置,不存在则返回-1
    print(f,g)
    h=' ' in s
    print(h)#用in 方法判断字符串内是否存在指定内容
    i=s.rfind(' ')#从右边开始寻找
    print(i)
    j=s.startswith('#')
    k=s.endswith('!')
    print(j,k)

    >>>>

    3 1
    True
    5
    False True

  • 相关阅读:
    sgu114Telecasting station
    UVA11748 Rigging Elections (dfs)
    UVA11080Place the Guards (二分图染色)
    修复损坏的COM+目录
    iis增加对flv的支持
    CRM开发中的小技巧
    CRM中代理商,招商专员,招商经理,公司内部员工权限描述
    使用js为DataGrid设定行
    文档和在线视频开发
    网站数据采集
  • 原文地址:https://www.cnblogs.com/python1988/p/12116082.html
Copyright © 2011-2022 走看看