Click here to load reader
Upload
alexey-bovanenko
View
42
Download
0
Embed Size (px)
Citation preview
Pythonstr
Бованенко Алексей[email protected]
Python. Str● capitalize()● lower()● upper()● find(char, [start])● split()● join()● lstrip()● rstrip()● strip()
Python. str. capitalize()
● s = ‘hello, world!’● s.capitalize()
○ ‘Hello, world’
Python. str. upper()
● s = ‘hello, world’● s.upper()
○ 'HELLO, WORLD'
Python. str. lower()
● s = ‘HELLO, WORLD’● s.lower()
○ 'hello, world'
Python. str. find()
● find(sub [,start [,end]]) -> int○ -1 on failure
● s = ‘hello, world!’● s.find(‘l’)
○ 2● s.find(‘l’,5)
○ 10
Python. str. split()● split([sep [,maxsplit]]) -> list of strings● s = ‘hello, my world!’● s.split()
○ ['hello,', 'my', 'world!']● s.split(',')
○ ['hello', ' my world!']● s.split('l')
○ ['he', '', 'o, my wor', 'd!']● s.split('l',1)
○ ['he', 'lo, my world!']
Python. str. join()
● join(iterable) -> string● s = ‘hello, my world!’● s.split()
○ l = s.split()○ ['hello,', 'my', 'world!']
● '#'.join(l)○ 'hello,#my#world!'
Python. str. lstrip(), rstrip(), strip()● s = ‘ hello ’● s.lstrip()
○ 'hello '● s.rstrip()
○ ' hello'● s.strip()
○ 'hello'● s='hello,'● s.strip('h,')
○ 'ello'
Спасибо за внимание
Вопросы?