In [1]:
print ("hello,world!")


hello,world!

the python notebook hello

using markdown

hellohello


In [4]:
for i in range(3):
   print("the number is=%d"%(i))


the number is=0
the number is=1
the number is=2

In [6]:
for i in range(20):
    if(i<10):
        print("the num is less than 10---%d"%(i))
    elif(i==10):
        print ("the num is =10---%d"%(i))
    else:
        print("the num is greater than 10---%d"%(i))


the num is less than 10---0
the num is less than 10---1
the num is less than 10---2
the num is less than 10---3
the num is less than 10---4
the num is less than 10---5
the num is less than 10---6
the num is less than 10---7
the num is less than 10---8
the num is less than 10---9
the num is =10---10
the num is greater than 10---11
the num is greater than 10---12
the num is greater than 10---13
the num is greater than 10---14
the num is greater than 10---15
the num is greater than 10---16
the num is greater than 10---17
the num is greater than 10---18
the num is greater than 10---19

In [7]:
def hello():
    print("hello,world!!!")
hello()


hello,world!!!

In [11]:
def hello(name='ntini'):
    print ("your name is %s"%(name))
hello()
hello('nitin')


your name is ntini
your name is nitin

In [12]:
animals=[]
animals.append("bear")
animals.append("lion")
animals.append("monkey")
animals.append("unicorn")

print(animals)


['bear', 'lion', 'monkey', 'unicorn']

In [15]:
animals=["bear","lion","monkey","unicorn"]
print (animals)


['bear', 'lion', 'monkey', 'unicorn']

In [16]:
print (animals[0])


bear

In [17]:
for animal in animals:
    print(animal)


bear
lion
monkey
unicorn

In [18]:
a=animals.pop()
print(a)
print(animals)


unicorn
['bear', 'lion', 'monkey']

In [20]:
animals.append("bear")
print (animals)
animals.count("bear")


['bear', 'lion', 'monkey', 'bear', 'bear']
Out[20]:
3

In [21]:
animals.pop()


Out[21]:
'bear'

In [22]:
print(animals)


['bear', 'lion', 'monkey', 'bear']

In [23]:
print(animals)
new=[a for a in animals if a!="bear"]


['bear', 'lion', 'monkey', 'bear']

In [25]:
print(new)


['lion', 'monkey']

In [26]:
new=[a.upper() for a in animals if a!="bear"]
print (new)


['LION', 'MONKEY']

In [30]:
import random
#generate a random variable
random.randint(0,10)


Out[30]:
5

In [31]:
import numpy as np
np.power(2,2)


Out[31]:
4

In [33]:
from random import *
randint(0,10)


Out[33]:
10

In [34]:
import numpy as np
import matplotlib.pyplot as plt

X=np.linspace(-np.pi,np.pi,256,endpoint=True)
C,S=np.cos(X),np.sin(X)

plt.plot(X,C)
plt.plot(X,S)

plt.show()



In [ ]: