Integer expressions

In [1]:
1 + 1
Out[1]:
2
In [2]:
2 + 3
Out[2]:
5
In [3]:
5 * 2
Out[3]:
10
In [4]:
5 / 2
Out[4]:
2.5
In [5]:
5 // 2
Out[5]:
2

Logical expressions

In [6]:
True and False
Out[6]:
False
In [7]:
True or False
Out[7]:
True
In [8]:
5 == 5
Out[8]:
True
In [9]:
3 > 7
Out[9]:
False

String expressions

In [10]:
'Hello'
Out[10]:
'Hello'
In [11]:
'World'
Out[11]:
'World'
In [12]:
"Hello World"
Out[12]:
'Hello World'
In [13]:
'Hello' + 'World'
Out[13]:
'HelloWorld'
In [14]:
'Hello ' + 'World'
Out[14]:
'Hello World'
In [15]:
'Hello '*5
Out[15]:
'Hello Hello Hello Hello Hello '
In [16]:
1 + 2.14
Out[16]:
3.14
In [17]:
True + 2.14
Out[17]:
3.14
In [18]:
'Hello ' + 3.14
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-135b4616d73d> in <module>
----> 1 'Hello ' + 3.14

TypeError: must be str, not float
In [19]:
'Hello ' + str(3.14)
Out[19]:
'Hello 3.14'

import module

In [20]:
import math
math.pi
Out[20]:
3.141592653589793

Zen of Python

In [21]:
import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
In [ ]: