Python/String: Difference between revisions
< Python
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
= Using statements = | = Using statements = | ||
{| class="wikitable" | {| class="wikitable" | ||
! | ! || Code | ||
|- | |- | ||
| Length | | Length | ||
| Line 10: | Line 10: | ||
|- | |- | ||
| Substring | | Substring | ||
<source lang="python"> | | <source lang="python"> | ||
s = '2018-01-01' | s = '2018-01-01' | ||
s[:4] | s[:4] | ||
Revision as of 16:52, 21 March 2018
Using statements
| Code | |
|---|---|
| Length |
len(s)
|
| Substring | s = '2018-01-01'
s[:4]
s[5:]
s[5:7]
|
Using methods
| Sample | |
|---|---|
| bytes => str | b'abc'.decode('utf-8)
|
| Prefix & Suffix | if s.startswith(): ...
if s.endswith(): ...
|