python-内置数据结构2
In : lst = ['i','am','martin']In : lst
Out: ['i', 'am', 'martin']
In : ' '.join(lst)
Out: 'i am martin'
In :
In : s = 'i love python'
In : s.split()
Out: ['i', 'love', 'python']
In : ' love python'.split()
Out: ['love', 'python']
In : ' love python'.split(' ')
Out: ['', '', '', '', '', '', 'love', 'python']
In : s.split(maxsplit=1)
Out: ['i', 'love python']
In : s = '''i am martin
...: i love python'''
In : s.splitlines()
Out: ['i am martin', 'i love python']
In : 'i am martin'.partition(' ')
Out: ('i', ' ', 'am martin')
In : cfg = 'env = PATH=/usr/bin;$PATH'
In : cfg.partition('=')
Out: ('env ', '=', ' PATH=/usr/bin;$PATH')
In : s = 'test'
In : s.upper()
Out: 'TEST'
In : s.upper().lower()
Out: 'test'
In : s.title()
Out: 'Test'
In : s.center(30)
Out: ' test '
In : s = 'hahahah hehe'
In : s.strip()
Out: 'hahahah hehe'
页:
[1]