In [2]:
print("Hello World!")
In [18]:
x=8
In [19]:
type(x)
Out[19]:
In [20]:
x.bit_length()
Out[20]:
In [21]:
x=3.14159
In [22]:
type(x)
Out[22]:
In [23]:
x=0.25
In [24]:
x.as_integer_ratio()
Out[24]:
In [25]:
x="text"
In [26]:
x='text'
In [30]:
x="""
"Hello"
"""
In [32]:
x
Out[32]:
In [33]:
x=(2,3,4,"text")
In [34]:
x[0]
Out[34]:
In [35]:
x[1]
Out[35]:
In [36]:
x[3]
Out[36]:
In [37]:
x[-1]
Out[37]:
In [38]:
x[-2]
Out[38]:
In [39]:
x=[2,4,6]
In [40]:
x.append(8)
In [41]:
x
Out[41]:
In [42]:
x.pop()
Out[42]:
In [43]:
x
Out[43]:
In [44]:
x.pop(0)
Out[44]:
In [45]:
x
Out[45]:
In [49]:
x={"key":"value", "cat":"a samll animal"}
In [50]:
x
Out[50]:
In [51]:
x['cat']
Out[51]:
In [53]:
x['dog']="a larger animal"
In [54]:
x
Out[54]:
In [56]:
x.get("duck", "not found")
Out[56]:
In [57]:
for i in [2,4,6,8]:
print(i)
In [62]:
for i in range(2,11,2):
print(i)
In [66]:
i=0
while i<4:
print(i)
i+=1
In [69]:
def f(x):
return x*x
In [70]:
f(3)
Out[70]:
In [71]:
g=f
In [72]:
g(5)
Out[72]:
In [73]:
def h(x=0):
y=2*x
return y
In [74]:
h(3)
Out[74]:
In [75]:
h()
Out[75]:
In [76]:
with open("fibo_input.txt","r") as fp:
s=fp.read()
In [82]:
n=[]
for i in s.split():
n.append(int(i))
In [83]:
n
Out[83]:
In [84]:
%%timeit -n1
with open("fibo_input.txt","r") as fp:
s=fp.read()
n=[]
for i in s.split():
n.append(int(i))
In [109]: