In [1]:
print ("hello,world!")
In [4]:
for i in range(3):
print("the number is=%d"%(i))
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))
In [7]:
def hello():
print("hello,world!!!")
hello()
In [11]:
def hello(name='ntini'):
print ("your name is %s"%(name))
hello()
hello('nitin')
In [12]:
animals=[]
animals.append("bear")
animals.append("lion")
animals.append("monkey")
animals.append("unicorn")
print(animals)
In [15]:
animals=["bear","lion","monkey","unicorn"]
print (animals)
In [16]:
print (animals[0])
In [17]:
for animal in animals:
print(animal)
In [18]:
a=animals.pop()
print(a)
print(animals)
In [20]:
animals.append("bear")
print (animals)
animals.count("bear")
Out[20]:
In [21]:
animals.pop()
Out[21]:
In [22]:
print(animals)
In [23]:
print(animals)
new=[a for a in animals if a!="bear"]
In [25]:
print(new)
In [26]:
new=[a.upper() for a in animals if a!="bear"]
print (new)
In [30]:
import random
#generate a random variable
random.randint(0,10)
Out[30]:
In [31]:
import numpy as np
np.power(2,2)
Out[31]:
In [33]:
from random import *
randint(0,10)
Out[33]:
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 [ ]: