Update README.md
Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
parent
02cbeeb067
commit
54178b8fb0
1 changed files with 67 additions and 0 deletions
|
@ -13,6 +13,62 @@
|
|||
Questions to [David Rotermund](mailto:davrot@uni-bremen.de)
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
### Input / Print
|
||||
|
||||
```python
|
||||
a = input() # <- test
|
||||
print(a) # -> test
|
||||
```
|
||||
|
||||
### String to int
|
||||
|
||||
```python
|
||||
a = int(5)
|
||||
print(a) # -> 5
|
||||
print(type(a)) # -> <class 'int'>
|
||||
a = int(-5)
|
||||
print(a) # -> -5
|
||||
print(type(a)) # -> <class 'int'>
|
||||
a = int("5")
|
||||
print(a) # -> 5
|
||||
print(type(a)) # -> <class 'int'>
|
||||
a = int("-5")
|
||||
print(a) # -> -5
|
||||
print(type(a)) # -> <class 'int'>
|
||||
a = int(" 5 ")
|
||||
print(a) # -> 5
|
||||
print(type(a)) # -> <class 'int'>
|
||||
a = int("3.4") # ValueError: invalid literal for int() with base 10: '3.4'
|
||||
a = int("Hello") # ValueError: invalid literal for int() with base 10: 'Hello'
|
||||
```
|
||||
|
||||
### String to float
|
||||
|
||||
```python
|
||||
a = float(5)
|
||||
print(a) # -> 5.0
|
||||
print(type(a)) # -> <class 'float'>
|
||||
a = float(5.1)
|
||||
print(a) # -> 5.1
|
||||
print(type(a)) # -> <class 'float'>
|
||||
a = float(-5.1)
|
||||
print(a) # -> -5.1
|
||||
print(type(a)) # -> <class 'float'>
|
||||
a = float("5.1")
|
||||
print(a) # -> 5.1
|
||||
print(type(a)) # -> <class 'float'>
|
||||
a = float("-5.1")
|
||||
print(a) # -> -5.1
|
||||
print(type(a)) # -> <class 'float'>
|
||||
a = float(" 5.1 ")
|
||||
print(a) # -> 5.1
|
||||
print(type(a)) # -> <class 'float'>
|
||||
a = float("Hello") # ValueError: could not convert string to float: 'Hello'
|
||||
```
|
||||
|
||||
|
||||
## [input](https://docs.python.org/3/library/functions.html#input)
|
||||
|
||||
```python
|
||||
|
@ -90,3 +146,14 @@ floatvalue ::= [sign] (floatnumber | infinity | nan)
|
|||
>
|
||||
> If no argument is given, 0.0 is returned.
|
||||
|
||||
## [type](https://docs.python.org/3/library/functions.html#type)
|
||||
|
||||
```python
|
||||
class type(object)
|
||||
class type(name, bases, dict, **kwds)
|
||||
```
|
||||
|
||||
> With one argument, return the type of an object. The return value is a type object and generally the same object as returned by object.\_\_class\_\_.
|
||||
>
|
||||
> **The isinstance() built-in function is recommended for testing the type of an object, because it takes subclasses into account.**
|
||||
|
||||
|
|
Loading…
Reference in a new issue