Corrections - Tom
Compare changes
- Tom Reclik authored
+ 14
− 0
The simplest is to invoke the interactive shell by just typing ```python``` on the command line. This will allways work whenever we have an python interpreter installed and we will get the characteristic prompt ```>>>```. However, it is not very convenient to use as it does not allow a rich history or editing. You can leave this shell by either typing ```quit()``` or ```CTRL+D``` (for EOF: End-Of-File). ```ipython``` is an enhanced interactive shell that is a good way to interact with python whenever we need to do so from the command line.
```
```
```
```
```
```
We can see that python has inferred that we are using integers here. Python uses the concept of "dynamic typing" which means that the type of the variable is only determined at run-time (when the code is excecuted). Other languagues, such as, e.g. C++, use "strong typing" where the type of the variable has to be defined when the code is written (e.g.: ```int short_type = 7```).
As always - dynamic typing has advantages and disadvantages: It is obviously very easy to use as we see above and we can also write quite flexible code that operates on a range of types. For example, if we had written ```short_side = 7.0``` we would have obtained a float variable. Our code would do the same, in python, it even is the same code, in other languages, we have to be more stringent.
> Try to name the variables such that their name reflects their purpose. We could have written ```x=7``` and ```y=10``` but then we would probably have forgotten what ```x``` and ```y``` stand for immediately. we could also have written ```short=7``` and ```long=10```. This would have been a bit better - but if we have a few more variables, we would probably wonder what we refer to as ```long``` and ```short```...
```
```
```
```
```
```
```
```
```
```