Exercise sheet \(1\):¶
(i). Predict the output of following expressions.
(ii). Type them on Python shell and compare with your predictions.
Expresión |
Predicción |
Salida |
Tipo |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In an assignment statement, python evaluates the right-hand side first, before doing the actual setting of variables. Before typing following lines on shell, write your prediction in the dotted areas.
NumPy is the fundamental package for scientific computing with Python. It contains among other things:
A powerful N-dimensional array object.
Sophisticated (broadcasting) functions.
Tools for integrating C/C++ and Fortran code.
Useful linear algebra, Fourier transform, and random number capabilities.
SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible.
Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms.
pandas is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language.
a) 5 <class 'int'>
b) 6.0 <class 'float'>
c) 2.0 <class 'float'>
d) -2.0 <class 'float'>
e) -2 <class 'int'>
f) 0 <class 'int'>
g) 0.0 <class 'float'>
h) 0.0 <class 'float'>
i) 0 <class 'int'>
j) -2.0 <class 'float'>
k) 14 <class 'int'>
l) 18 <class 'int'>
m) ab <class 'str'>
n) a3 <class 'str'>
o) 1 <class 'int'>
p) 0 <class 'int'>
q) 2 <class 'int'>
1 2 3 | >>> x, y = 1, 2
>>> x = y
>>> y = x + y
|
>>> x, y = 1, 2
>>> x, y = y, x + y
>>> x
2
>>> y
3
>>> first = 'world'
>>> last = 'hello'
>>> print(last + ', ' + first)
hello, world
>>> print(last, ',', first)
hello , world
