In [3]:
import numpy as np
In [5]:
from numpy import pi
In [7]:
from numpy import *
In [8]:
import numpy.linalg as la
In [2]:
numpy.pi
Out[2]:
In [4]:
np.pi
Out[4]:
In [6]:
pi
Out[6]:
In [23]:
%%file foo.py
def bar():
print('hi')
if __name__ == '__main__':
bar()
In [10]:
! ls
In [11]:
import foo
In [13]:
foo.bar()
In [14]:
from foo import bar
In [15]:
bar()
In [17]:
! python foo.py
In [18]:
f = open('foo.py', 'r')
print(f.read())
f.close()
In [20]:
with open('foo.py', 'r') as f:
print(f.read())
In [24]:
with open('foo.py', 'r') as f:
lines = f.readlines()
In [25]:
lines
Out[25]:
In [26]:
line = lines[0]
In [27]:
line
Out[27]:
In [30]:
line = line.strip()
In [31]:
line
Out[31]:
In [32]:
line.lower()
Out[32]:
In [33]:
line.upper()
Out[33]:
In [34]:
line.title()
Out[34]:
In [35]:
lines
Out[35]:
In [36]:
''.join(lines)
Out[36]:
In [37]:
'XXX'.join(lines)
Out[37]:
In [39]:
fubar = '-'.join(['foo', 'bar', 'baz'])
In [40]:
fubar
Out[40]:
In [41]:
fubar.split('-')
Out[41]:
In [43]:
s = ''.join(lines)
s.split()
Out[43]:
In [47]:
from string import punctuation
In [48]:
punctuation
Out[48]:
In [51]:
s = ''.join(lines)
In [52]:
s
Out[52]:
In [53]:
for char in punctuation:
s = s.replace(char, '')
In [54]:
s
Out[54]:
In [55]:
s = ''.join(lines)
In [56]:
table = dict.fromkeys(map(ord, punctuation))
In [58]:
s
Out[58]:
In [59]:
s.translate(table)
Out[59]:
In [62]:
s
Out[62]:
In [63]:
s[5:10]
Out[63]:
In [65]:
s.find('bar')
Out[65]:
In [66]:
s.rfind('bar')
Out[66]:
In [ ]: