zoukankan      html  css  js  c++  java
  • python字符串的含义

    #!/usr/bin/python3
    name="my    name is xiAngXiao"
    name2="alex"
    name3="my {name} is xiangxiao,and my {yeae} is"
    #print(name.capitalize())#将首字母都大写
    #print(name.center(50,"-"))#name放中间,两边加上-符号
    #print(name2.endswith(ex))#判断name2是否以ex结尾
    #print(name.expandtabs(tabsize=50))#将tab键转换成多少个空格
    #print(name.find("y"))#返回y的位置
    #print(name[name.find("y"):9])#从y的位置到9之前的所有字符
    #print(name3.format(name='xiangxiao',yeae=26))#格式化并且赋值
    #print(name.format_map({'name':'alex','yeae':26}))
    #print('abc123'.isalnum())#判断是否包含字符和数字,返回True,如果有特殊字符返回false
    #print('abA'.isalpha())#纯英文字符,大小写均可
    #print('1A'.isdecimal())#十进制的判断
    #print('1'.isdigit())#判断是否是数字
    #print('1A'.isidentifier())#标示符的判断
    #print('33'.isnumeric())#判断是否有小数点
    #print('My Name IS'.istitle())#首写字符是否大写
    #print(','.join(['1','2','3']))#将中括号中的内容加到单引号,并且用都好隔开
    #print(name.ljust(50,'*'))#名字在左边,右边用*号补齐够50个
    #print(name.rjust(50,'*'))#名字在右边,左边用*号补齐
    #print('Alex'.lower())#所有字母小写
    #print('Alex'.upper())#所有字母大写
    #print('Alex '.lstrip())#去掉左边的空格和回车
    #print(' Alex'.rstrip())#去掉右边的空格和回车
    #print(' Alex '.strip())#去掉空格和回车
    #print('---')
    #p=str.maketrans("abcefg","123456")
    #print("xiangx".translate(p))#将对应的字母翻译成数字
    #print('xiangxiao'.replace('x','X',1))#将第一个小写x改成大写X
    #print('xiangxiao'.rfind('x'))#返回最后一个x的位置
    #print('1+2+3+4'.split('+'))#以+号为分隔符,
    #print('1+2 +3+4'.splitlines())#以 为分隔符
    #print('xiangxiao'.title())#首写字母大写
    #print('lexli'.zfill(50))#用0填充左边

     

    字典的使用:

    例:

    info={

    stu1001:wangbo,

    stu1002:xiangxiao,

    stu1003:xiongyuhang

    }

    b={“stu1101”:”alex”,1:2,3:4}

    #print(info) #打印字典

    c=dic.fromkeys([6,7,8],test)#中括号是key,双引号对应取值

    c=dic.fromkeys([6,7,8],[1,{name:alex},2])

    c[7][1][name]=jackchen#alex的改为jackchen

    for i in info:

    print(i,info[i])

    2:三级菜单:

     

    data={'广州':{'天河':['天河体育馆','天河大厦'],#初始化地名
                        '越秀':['越秀公园','光孝寺'],
                        '番禹':['长龙幻世界','大夫山']},
               '陕西':{'西安':['长安','雁塔'],
                        '商洛':['商南','山阳'],
                        '汉中':['汉台','南镇']},
                '上海':{'浦东':['枫桥','孔庙'],
                        '南海':['千灯湖','南国桃园'],
                        '顺德':['清晖园','西山庙']}}
    ex_flag=False
    while not ex_flag:
        for i in data:
            print(i)
        choice=input("请选择地方>>")
        if choice in data:
            while not ex_flag:
                for i2 in data[choice]:
                    print(" ",i2)
                choice2=input("请选择地方2>>")
                if choice2 in data[choice]:
                    while not ex_flag:
                        for i3 in data[choice][choice2]:
                            print(" ",i3)
                        choice3=input("请选择地方3>>")
                        if choice3 in data[choice][choice2]:
                            pass
                        if choice3=="b":
                            break
                        if choice3=="q":
                            ex_flag=True

                if choice2=="b":
                    break
                elif choice2=="q":
                    ex_flag=True
        if choice=="q" :
            ex_flag=True

     

  • 相关阅读:
    微信支付Native扫码支付模式二之CodeIgniter集成篇
    如何使用硬盘安装debian8.3?
    使用git将代码push到osc上
    树莓派(Raspberry Pi)搭建简单的lamp服务
    win下修改mysql默认的字符集以防止乱码出现
    CodeIgniter2.2.0-在控制器里调用load失败报错的问题
    Ubuntu Server(Ubuntu 14.04 LTS 64位)安装libgdiplus2.10.9出错问题记录
    linux下mono的安装与卸载
    asp.net中ashx生成验证码代码放在Linux(centos)主机上访问时无法显示问题
    使用NPOI将数据导出为word格式里的table
  • 原文地址:https://www.cnblogs.com/pythonbz/p/6283994.html
Copyright © 2011-2022 走看看