Python/String: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
Line 3: Line 3:
!
!
|-
|-
|  
| Length
|
<source lang="python">
len(s)
</source>
|-
|-
|
| Substring
<source lang="python">
s = '2018-01-01'
s[:4]
s[5:]
s[5:7]
</source>
|-
|-
|}
|}

Revision as of 16:52, 21 March 2018

Using statements

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(): ...