Python/String: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
Line 42: Line 42:
</source>
</source>
|-
|-
| Joinning & Splitting
| To Join & Split
| <source lang="python">
</source>
|-
| To trim
| <source lang="python">
| <source lang="python">
</source>
</source>
|}
|}

Revision as of 16:57, 21 March 2018

Using statements

Code
Length
len(s)
Substring
s = '2018-01-01'
s[:4]
s[5:]
s[5:7]
Has substring
if '18' in '2018-01-01': ...

Using methods

Sample
bytes => str
b'abc'.decode('utf-8)
Prefix & Suffix
if s.startswith(): ...
if s.endswith(): ...
Formatting
To Join & Split
To trim