zoukankan      html  css  js  c++  java
  • 2018.12.4 python基础——字符串的魔法

    一、安装pycharm5.0.3版本

    二、in 与not in

    name="郑建文"
    #"郑建文"——字符串
    #"郑建"——子字符串(子序列)
    #"郑"——字符
    if""in name:
        print('ok')
    else:
        print('error')

    三、布尔值——数据类型之三(还有:数字,字符串)

    v=1==1
    print(v)
    
    
    运行
    true

     四、数据类型以及其类功能详细:

    1.数字 int   2.元组 tuple  3.列表 list   4.字典 dict  5.字符串 str  6.布尔值 bool

    五、数字的功能:

    1.int

    例1:

    num='a'
    v=int(num,base=16)
    print(v)

    输出:10——基于16进制,将A转换为十进制

    例2:

    num='36ABC'
    v=int(num,base=16)
    print(v)

    输出:223932——基于16进制,将36ABC转换为十进制

     2.bit_legth

    二、字符串的功能:

    1.count

    2.capitalize

    3.casefold

    4.lower

    5.center

    6.endswith,startswith

    7.find

    8.format

     9.format_map

    10.index

    11.isalnum

    12.expandtabs

    借助它可以制作表格

    test='uesrname	age	date
    abc	13	33.3
    abc	13	33.3
    abc	13	33.3'
    v=test.expandtabs(20)
    print(v)

    13.isalpha

    14.isdecimal,isdigit

    15.isidentifier

    16.islower

    17.isnumeric

    18.isprintable

    19.isspace

    20.istitle,title

    21.join

    22.ljust,rjust,zfill

    23.lower

    24.lstrip,rstrip,strip

    25.maketrans,translate

    26.partition,rpartition,split,rsplit

    27.splitlines

    28.startswith,endswith

    29.swapcase

    30.replace

    7个基本用法必须会!!:join     split   strip   lower  upper  find   replace

     

     三、字符串附加用法:

    1.for循环

    2.切片

    3.索引/下标

    4.len

    注意:join ,切片,索引,len,for循环这五个是所有的数据类型都会用到。

     操作notpadd++的之后,设置行注释——快捷键:ctrl+k

                                            设置行注释——快捷键:ctrl+shift+k

     练习题:将test="pwe“的三个字母的对应的索引(如:p对应0;w对应1;e对应2)全部打印出来

    # 方法一:
    
    # test=input(">>>")
    # print(test)
    # t=len(test)
    # print(t)
    # r=range(0,t)
    # print(r)
    # for item in r:
        # print(item)
        
        
    test=input(">>>")
    print(test)
    t=len(test)
    print(t)
    r=range(0,t)
    print(r)
    for item in r:
        print(item,test[item])

    输出:
    
    
    # 方法二:
    
    test=input('>>>')
    for item in range(0,len(test)):  #将“range”整体比作一个字符串!
      print(item,test[item])

    输出:
    
    
  • 相关阅读:
    7、.net core 使用apollo
    6、初识Apollo
    5、supervisor安装使用
    Linux用户和用户组管理
    监督学习中的“生成模型”和“判别模型”
    Ubuntu 14.04 installation & bugs on Alienware-13
    Majority Element问题---Moore's voting算法
    redis之作为缓存的使用(二)
    redis之作为缓存的使用(五)缓存污染
    redis之作为缓存的使用(四)缓存击穿,雪崩,穿透
  • 原文地址:https://www.cnblogs.com/lijialun/p/10062476.html
Copyright © 2011-2022 走看看