zoukankan      html  css  js  c++  java
  • python string method

    嗯,学习其它语言没这样全练过,嘻嘻

    //test.py

    1 # -*- coding: UTF-8 -*-
    2
    3 str = "i am worker"
    4 print str.capitalize()
    5 print str.center(20)
    6 print str.count(' ')
    7 print str.count(' ', 0, 4)
    8 str1 = "中国"
    9 str1.decode('utf-8').encode('gb2312')
    10 print str1
    11 str2 = u'中国'
    12 str2.encode('gb2312')
    13 print str2
    14 print str.endswith('er')
    15 print str.endswith('er', 0, 6)
    16 str3 = '1 3 5'
    17 print str3
    18 print str3.expandtabs()
    19 print str3.expandtabs(1)
    20 print str.find('m', 0, len(str))
    21 #print str.index('h', 0, len(str)) #exception
    22 print ''.isalnum()
    23 print '?1a'.isalnum()
    24 print '1a'.isalnum()
    25 print '1'.isalpha()
    26 #print 'isdecimal', '1a'.isdecimal() #no implement
    27 print 'isdigit', '1a'.isdigit()
    28 #print 'isnumeric', '1a'.isnumeric() #no implement
    29 print 'islower', '1a'.islower()
    30 print ' '.isspace()
    31 print 'You are fool'.istitle()
    32 print 'You Are Fool'.istitle()
    33 print '1a'.isupper()
    34 print 'and'.join(['1', '2', '3'])
    35 print '123'.ljust(10) #make no sense of
    36 print 'ABC'.lower()
    37 print 'abc'.upper()
    38 print ' abAB'.lstrip()
    39 #print '123abc'.maketrans('123', 'ABC') #no implement
    40 print '123'.partition('2')
    41 print '123'.partition('1')
    42 print '123'.partition('3')
    43 print '123'.partition('4')
    44 print '113'.replace('1', '2')
    45 print '113'.replace('1', '2', 1)
    46 print '11a'.rfind('a')
    47 print '11a'.rindex('a')
    48 print '123'.rjust(8)
    49 print '123'.rpartition('2')

    50 print '123 '.rstrip()
    51 print '12134'.split('1')
    52 print '12134'.split('1', 1)
    53 print '1 2 3 '.splitlines(True)
    54 print '1 2 3 '.splitlines(False)
    55 print '123'.startswith('1')
    56 print ' 123 '.strip()
    57 print 'AbAbAb'.swapcase()
    58 print 'abc def hgj'.title()
    59 print '1aAbB?><'.translate(None, '<>')
    60 print '123'.zfill(8)
    61 print u'123'.isdecimal()
    62 print u'AEBF'.isdecimal()

    //result

    # python test.py
    I am worker
    i am worker
    2
    1
    中国
    中国
    True
    False
    1 3 5
    1 3 5
    1 3 5
    3
    False
    False
    True
    False
    isdigit False
    islower True
    True
    False
    True
    False
    1and2and3
    123
    abc
    ABC
    abAB
    ('1', '2', '3')
    ('', '1', '23')
    ('12', '3', '')
    ('123', '', '')
    223
    213
    2
    2
    123
    ('1', '2', '3')
    123
    ['', '2', '34']
    ['', '2134']
    ['1 ', '2 ', '3 ']
    ['1', '2', '3']
    True
    123
    aBaBaB
    Abc Def Hgj
    1aAbB?
    00000123
    True

    False

    Finally:

    肯定有你用得着的

  • 相关阅读:
    failed to push some refs to 'git@github.com:laniu/liuna.git'报错原因
    ECMAScript和JavaScript的关系
    js面试总结
    第16章 脚本化css
    代理模式
    SQL
    VS
    Js/Jquery获取iframe中的元素 在Iframe中获取父窗体的元素方法
    SQL
    C#
  • 原文地址:https://www.cnblogs.com/woodzcl/p/7779377.html
Copyright © 2011-2022 走看看