Browse Source

Format, try else

pull/3/head
Jure Šorn 6 years ago
parent
commit
7fde6bc38b
1 changed files with 24 additions and 4 deletions
  1. 28
      README.md

28
README.md

@ -29,6 +29,11 @@ sorted_by_second = sorted(<list>, key=lambda el: el[1])
flattened_list = [item for sublist in <list> for item in sublist] flattened_list = [item for sublist in <list> for item in sublist]
``` ```
```python
>>> list('ABC')
['A', 'B', 'C']
```
Dictionary Dictionary
---------- ----------
```python ```python
@ -156,11 +161,11 @@ String
------ ------
```python ```python
str.replace(text, old, new) str.replace(text, old, new)
<str>.isnumeric()
<str>.split(sep=None, maxsplit=-1) <str>.split(sep=None, maxsplit=-1)
<str>.strip() <str>.strip()
<str>.join(<list>) <str>.join(<list>)
<str>.startswith(<str>) <str>.startswith(<str>)
<str>.isnumeric()
``` ```
### Print ### Print
@ -199,7 +204,7 @@ re.split(<regex>, text, maxsplit=0) # Use brackets in regex to keep the matches
{:min_width} # '<el> ' {:min_width} # '<el> '
{:>min_width} # ' <el>' {:>min_width} # ' <el>'
{:^min_width} # ' <el> ' {:^min_width} # ' <el> '
{:_min_width} # '<el>____'
{:_<min_width} # '<el>____'
{:.max_width} # '<e>' {:.max_width} # '<e>'
``` ```
```python ```python
@ -219,6 +224,19 @@ re.split(<regex>, text, maxsplit=0) # Use brackets in regex to keep the matches
'187' '187'
``` ```
```python
>>> f'{123:020b}'
'00000000000001111011'
```
#### Integer presentation types:
* 'b' - binary
* 'c' - character
* 'o' - octal
* 'x' - hex
* 'X' - HEX
### Text Wrap ### Text Wrap
```python ```python
import textwrap import textwrap
@ -239,7 +257,7 @@ random.choice(<list>)
Infinity Infinity
-------- --------
```python ```python
float("inf")
float('inf')
``` ```
Datetime Datetime
@ -512,9 +530,11 @@ Exceptions
while True: while True:
try: try:
x = int(input("Please enter a number: ")) x = int(input("Please enter a number: "))
break
except ValueError: except ValueError:
print("Oops! That was no valid number. Try again...") print("Oops! That was no valid number. Try again...")
else:
print("Thank you.")
break
``` ```
Threading Threading

Loading…
Cancel
Save