This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Try from link https://try.jupyter.org/ | |
#Ref Tutorial - https://www.youtube.com/watch?v=1I2Bz0qbMsc | |
#Example #1 - python variables | |
#boolean | |
a = True | |
#int | |
b = 4 | |
#float | |
c = 3.45 | |
#complex | |
e = 7j | |
print(c) | |
print(e) | |
print(a) | |
print(b) | |
#Example 2 | |
name = "Siva" | |
print(name) | |
agelist=[1,2,3,4,5] | |
print(agelist) | |
agelist.append(10) | |
print(agelist) | |
dict_example={"name":"siva","credit":100} | |
print(dict_example["name"]) | |
dict_example.values() | |
#Example 3 - Integer Array | |
import numpy as np | |
a = np.arange(1,10) | |
a | |
#Example 4 - Integer Array | |
import numpy as np | |
ds = np.arange(1.2,10,2,dtype=np.float64) | |
ds | |
#Example 5 shape of array | |
import numpy as np | |
ds = np.arange(1.2,10,2,dtype=np.float64) | |
ds.shape | |
ds | |
#Example 6 Parsing list | |
agelist=[1,2,3,4,5,6,7,8,9,10] | |
#print first element | |
print(agelist[0]) | |
#print from 0 to 2 | |
print(agelist[0:2]) | |
#print from 2 onwards | |
print(agelist[2:]) | |
#print last element | |
print(agelist[-1]) | |
#print last two elements | |
print(agelist[-2:]) | |
#print start to last-1 | |
print(agelist[0:-1]) | |
#Example 7 | |
a = 10 | |
b = 3 | |
#Float result | |
print(a/b) | |
#Int result | |
print(a//b) | |
#Example 8 | |
#For loop | |
for counter in range(1,50,1): | |
print(counter) | |
#Example 9 | |
#While Loop | |
counter=1 | |
while counter<100: | |
print(counter) | |
counter=counter+1 | |
#Example 10 | |
#If conditions | |
a=9 | |
if a>10: | |
print("a > 10") | |
elif a<10: | |
print("a <10") | |
else: | |
print("a=10") | |
#Example 11 Functions | |
def computesquare(n): | |
return n*n | |
print(computesquare(10)) |
No comments:
Post a Comment