10

Click here to load reader

Python. Строки

Embed Size (px)

Citation preview

Page 1: Python. Строки

Pythonstr

Бованенко Алексей[email protected]

Page 2: Python. Строки

Python. Str● capitalize()● lower()● upper()● find(char, [start])● split()● join()● lstrip()● rstrip()● strip()

Page 3: Python. Строки

Python. str. capitalize()

● s = ‘hello, world!’● s.capitalize()

○ ‘Hello, world’

Page 4: Python. Строки

Python. str. upper()

● s = ‘hello, world’● s.upper()

○ 'HELLO, WORLD'

Page 5: Python. Строки

Python. str. lower()

● s = ‘HELLO, WORLD’● s.lower()

○ 'hello, world'

Page 6: Python. Строки

Python. str. find()

● find(sub [,start [,end]]) -> int○ -1 on failure

● s = ‘hello, world!’● s.find(‘l’)

○ 2● s.find(‘l’,5)

○ 10

Page 7: Python. Строки

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!']

Page 8: Python. Строки

Python. str. join()

● join(iterable) -> string● s = ‘hello, my world!’● s.split()

○ l = s.split()○ ['hello,', 'my', 'world!']

● '#'.join(l)○ 'hello,#my#world!'

Page 9: Python. Строки

Python. str. lstrip(), rstrip(), strip()● s = ‘ hello ’● s.lstrip()

○ 'hello '● s.rstrip()

○ ' hello'● s.strip()

○ 'hello'● s='hello,'● s.strip('h,')

○ 'ello'

Page 10: Python. Строки

Спасибо за внимание

Вопросы?