Definition: An expression is an construct of symbols that the python interpreter can evaluate. The expression we can type in the inpreter, and that the interpreter can evaluate meaningfully are
In [1]:
x = 5; y = 700; z = 821
In [2]:
x + y
x * y
x ** y
# etc.
Out[2]:
The simplest "textual expression" is a string, i.e., a sequence of characters (i.e., alphanumeric symbols, plus puntuation marks, plus special escape sequences).
To let python Know that your text is a string, and not the name of a variable, you need to use quotes:
In [3]:
"Once upon a time\nthere was a little rabbit\nwho liked carrots two much."
Out[3]:
In [4]:
"""Once upon a time
there was a little rabbit
who liked carrots two much
He said
I'd live another carrot"""
Out[4]:
In [8]:
x = "Benoit"
y = "Dherin"
z = x + ' ' + y
print z
In [12]:
x = "Hello "
8*x
Out[12]:
In [25]:
name = 'Bob'; age = 32; job ='Teacher'; teeth = 12.5
name2 = 'Marcelluscatapultus'; age2 = 3320; job2 ='Yogi'; teeth2 = 122.82
In [26]:
print name + job + str(age) + str(teeth)
In [41]:
formatted_string = "| %-20s | %-20s | %-4d | %-8.2f |" % (name, job, age, teeth)
formatted_string2 = "| %-20s | %-20s | %-4d | %-8.2f |" % (name2, job2, age2, teeth2)
print '_'* 65
print formatted_string
print formatted_string2
print '_'* 65
In [ ]:
In [6]:
True
Out[6]:
In [7]:
False
Out[7]:
In [20]:
x = True; y = False
In [23]:
x and y
Out[23]:
In [24]:
x or y
Out[24]:
In [25]:
not x
Out[25]:
In [26]:
(x or y) and not x
Out[26]:
In [ ]: