> For the complete documentation index, see [llms.txt](https://olexsyn.gitbook.io/enote/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olexsyn.gitbook.io/enote/progr/python/strings/ryadok-v-chislo.md).

# Рядок в число

int, float, isdecimal, isdigit, isnumeric

#### Чи є рядок числом? -  isdecimal(), isdigit(), isnumeric()&#x20;

```python
pin = "523"
# checks if every character of pin is numeric 
print(pin.isnumeric())  # True
```

<table data-header-hidden><thead><tr><th width="156"></th><th width="113"></th><th width="159"></th><th width="140"></th><th></th></tr></thead><tbody><tr><td>String Type</td><td>Example</td><td>Python <code>.isdecimal()</code></td><td>Python <code>.isdigit()</code></td><td>Python <code>.isnumeric()</code></td></tr><tr><td>Base 10 Numbers</td><td><code>'0123'</code></td><td>True</td><td>True</td><td>True</td></tr><tr><td>Fractions and Superscripts</td><td><code>'⅔', '2²'</code></td><td>False</td><td>True</td><td>True</td></tr><tr><td>Roman Numerals</td><td><code>'ↁ'</code></td><td>False</td><td>False</td><td>True</td></tr></tbody></table>

<https://datagy.io/python-isdigit/>

#### Перетворення рядка на ціле число **- int()**

```python
str_a = '50'
b = 10
c = int(str_a) + b
print ("The value of c = ",c)  
```

:exclamation: Але не можна використати int, якщо число в рядку не ціле!&#x20;

```python
strn = '-12,345678'
print( int( strn.replace(',', '.') ) )             # error!
print( round( float( strn.replace(',', '.') ) ) )  # -12
```

#### Перетворення рядка на число з плаваючою точкою **- float()**

```python
str_a = '50.85'
b = 10.33
c = float(str_a) + b
print ("The value of c = ",c)
```

:question: Як бути, якщо користувач введе кому замість крапки?

```python
strn = '-12,345678'
print( float( strn.replace(',', '.') ) )              # -12.345678
print( round( float( strn.replace(',', '.') ), 2 ) )  # -12.35 (з округленням)
```
