Skip to content

Commit bfcccc2

Browse files
committed
update
1 parent 90fe7c9 commit bfcccc2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Chapter_02: Functions, File IO, Generators.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,3 +913,44 @@ Returns an object of type enumerate from an iterable(e.g. lists or tuples).
913913

914914
**eval**
915915

916+
```python
917+
>>> help(eval)
918+
919+
eval(source, globals=None, locals=None, /)
920+
Evaluate the given source in the context of globals and locals.
921+
922+
The source may be a string representing a Python expression
923+
or a code object as returned by compile().
924+
925+
>>> eval('1+2')
926+
3
927+
>>> eval('a+2', {'a': 1})
928+
3
929+
>>> eval('f"a equal to {a}"', {'a': 1+2})
930+
'a equal to 3'
931+
```
932+
933+
**exec**
934+
935+
Executes a python script.
936+
937+
```python
938+
>>> exec('a = 2; print(a)')
939+
2
940+
>>> exec('f"a equal to {a}"', {'a': 1+2}) # returns nothing
941+
```
942+
943+
If you want to see the difference between eval, exec, and compile, you can refer to the following answer @[stackoverflow](https://stackoverflow.com/questions/2220699/whats-the-difference-between-eval-exec-and-compile), or you can read [python docs](https://docs.python.org/3.7/library/functions.html#eval) for more details about these functions.
944+
945+
**exit**
946+
947+
```python
948+
>>> exit
949+
Use exit() or Ctrl-D (i.e. EOF) to exit
950+
```
951+
952+
**filter**
953+
954+
Already described in [this section](#1.2.3).
955+
956+

0 commit comments

Comments
 (0)