In [1]:
print "hello world"
In [2]:
l = [1,2,3]
In [3]:
help(l)
In [ ]:
markdown test, i can write normal text here and it will not run as code!
In [4]:
# this is a comment and will not run in the code
In [5]:
'''this is just a mulit line comment'''
Out[5]:
In [6]:
pwd
Out[6]:
In [7]:
#addition
2+1
Out[7]:
In [8]:
# substraction
2-1
Out[8]:
In [9]:
1-2
Out[9]:
In [10]:
2*2
Out[10]:
In [11]:
3/2
Out[11]:
In [12]:
3.0/2
Out[12]:
In [13]:
float(3)/2
Out[13]:
In [14]:
3/float(2)
Out[14]:
In [18]:
from __future__ import division
3/2
Out[18]:
In [19]:
1/2
Out[19]:
In [20]:
2/3
Out[20]:
In [21]:
root(2)
In [22]:
sqrt(2)
In [23]:
4^2
Out[23]:
In [24]:
4^.5
In [25]:
4**.5
Out[25]:
In [26]:
a=5
In [27]:
a=6
a+a
Out[27]:
In [28]:
a
Out[28]:
In [29]:
0.1+0.2-0.3
Out[29]:
In [30]:
'hello'
Out[30]:
In [31]:
'this entire thing can be a string'
Out[31]:
In [32]:
"this is using double quotes"
Out[32]:
In [33]:
print 'hello'
In [34]:
print("hello")
In [35]:
s='hello'
In [36]:
s
Out[36]:
In [37]:
len(s)
Out[37]:
In [38]:
print(s)
In [39]:
s[3]
Out[39]:
In [40]:
s[10]
In [42]:
s[5]
In [47]:
s[2:4]
Out[47]:
In [48]:
z*10
In [49]:
letter='z'
letter*10
Out[49]:
In [50]:
letter.upper()
Out[50]:
In [52]:
letter.center('z')
In [53]:
print 'this is a string'
strings yoiu can use the %s to format strings into your print statements
In [55]:
s = 'STRING'
print 'place another string with a mod and s: %s' %(s)
In [56]:
from __future__ import print_function
In [57]:
print('hello')
In [58]:
print('one: {x}'.format(x='INSERT'))
In [59]:
my_list = [1,2,3,'o','29a jeoilapif a']
In [60]:
len(my_list)
Out[60]:
In [61]:
my_list[1:]
Out[61]:
In [62]:
my_list[1]+1
Out[62]:
In [63]:
my_list[1] = 5
In [64]:
my_list
Out[64]:
In [65]:
my_list + ['just a simple test'
]
Out[65]:
In [66]:
my_list * 2
Out[66]:
In [67]:
l = [1,2,3]
In [68]:
l.append('append me')
In [69]:
l
Out[69]:
In [70]:
l.pop(2)
Out[70]:
In [71]:
l
Out[71]:
In [72]:
l.pop()
Out[72]:
In [73]:
l
Out[73]:
In [74]:
l[100]
In [76]:
new_list = ['a','b','x','f','c']
In [77]:
new_list
Out[77]:
In [84]:
new_list.reverse()
In [87]:
new_list.reverse()
In [88]:
new_list
Out[88]:
In [89]:
lst_1 = [1,2,3]
lst_2 = [4,5,6]
lst_3 = [7,8,9]
matrix = [lst_1, lst_2, lst_3]
In [90]:
matrix
Out[90]:
In [93]:
matrix[2][1]
Out[93]:
In [94]:
first_col = [row[0] for row in matrix]
In [95]:
first_col
Out[95]:
In [98]:
my_dict = {'key1':'this is cool','key2':2, 'key3':'duh','key4':['a','b',3]}
In [99]:
my_dict['key4']
Out[99]:
In [102]:
my_dict.pop('key3')
Out[102]:
In [103]:
my_dict
Out[103]:
In [106]:
my_dict['key4'][1].upper()
Out[106]:
In [109]:
my_dict['key2'] -= 5
In [110]:
my_dict
Out[110]:
In [111]:
d = {}
In [112]:
d['animal'] = 'dog'
In [113]:
d
Out[113]:
In [116]:
d['answer']=421
In [117]:
d
Out[117]:
In [119]:
d.pop('anwer')
Out[119]:
In [120]:
d
Out[120]:
In [124]:
d = {'key 1':{'nestkey':{'subnestkey':'value'}}}
In [125]:
d
Out[125]:
In [127]:
d['key 1']['nestkey']['subnestkey']
Out[127]:
In [128]:
d = {'key1':1,'key2':2,'key3':3}
In [129]:
d.keys()
Out[129]:
In [130]:
d.values()
Out[130]:
In [131]:
d.items()
Out[131]:
In [132]:
t = (1,2,3)
In [133]:
len(t)
Out[133]:
In [134]:
t = ('one',2,'cool dude')
In [135]:
t
Out[135]:
In [136]:
t[1
]
Out[136]:
In [137]:
t[-1]
Out[137]:
In [138]:
t.index('one
')
In [139]:
t.index('one')
Out[139]:
In [140]:
t.count('one')
Out[140]:
In [141]:
t[0] = 'change'
In [142]:
t.append('nope')
In [144]:
pwd
Out[144]:
In [145]:
f = open('text_file.txt')
In [147]:
f.read()
Out[147]:
In [148]:
f.seek(0)
In [149]:
f.read()
Out[149]:
In [150]:
f.read()
Out[150]:
In [151]:
f.readlines()
Out[151]:
In [152]:
f.seek()
In [153]:
f.seek(0)
In [154]:
f.readlines()
Out[154]:
In [165]:
%%writefile new.txt
first line
second line
In [169]:
for line in open('new.txt'):
print('line')
In [ ]: