In [11]:
# This is some IPython %magic
%xmode plain
In [2]:
len("hello")
Out[2]:
In [1]:
"hello" + "!"
Out[1]:
In [3]:
"l" in "hello"
Out[3]:
In [4]:
"hello"[-3:]
Out[4]:
In [12]:
# Busted
count = 3
"Number of items: " + count
In [9]:
# OK, but there's a better way
name = "Peter"
greeting = "Hello"
"%s, %s, what's happenning?" % (greeting, name)
Out[9]:
In [13]:
"{}, {}, what's happenning?".format(greeting, name)
Out[13]:
In [18]:
print "Number of items: ---{:05}---".format(count)
print "Number of items: ---{:>5}---".format(count)
print "Number of items: ---{:<5}---".format(count)
In [26]:
from string import ascii_lowercase
print ascii_lowercase
a_f = list(ascii_lowercase[:6])
print a_f
letters = ", ".join(letters)
print letters
In [28]:
letters.split(", ")
Out[28]: