Skip to content

Instantly share code, notes, and snippets.

@creatorpiyush
Created September 8, 2019 10:20
Show Gist options
  • Save creatorpiyush/ffa7954ce3387e710f29349365a0bf59 to your computer and use it in GitHub Desktop.
Save creatorpiyush/ffa7954ce3387e710f29349365a0bf59 to your computer and use it in GitHub Desktop.
#arrays only specific type of data is used
import array
arr=array.array('i',[23,24,25])
print(arr)
print(arr[1])
arr=array.array('f',[23.5,24.7,25.3])
print(arr)
print(arr[1])
#2-D array
T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]
print(T[0])
print(T[1][2])
#reading full array
for r in T:
for c in r:
print(c,end = " ")
print()
print()
#for inserting an array
T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]
T.insert(2, [0,5,11,13,6])
for r in T:
for c in r:
print(c,end = " ")
print()
print()
#updating values
T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]
T[2] = [11,9]
T[0][3] = 7
for r in T:
for c in r:
print(c,end = " ")
print()
print()
#deleting the element from array
T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]
del T[3]
for r in T:
for c in r:
print(c,end = " ")
print()
print()
#len() for finding length of the function
name="Piyush"
print(len(name))
#upper() for upper case
print(name.upper())
#lower() foe lower case
print(name.lower())
#replace() we can replace one value to another
name2="Anand"
print(name.replace(name,name2))
#abs() to remove -ve from a number
num=-45
print(abs(num))
#str()
num=34
#print("the number is : "+num)#error
print("the number is : "+str(num))
#pow()
num=2
power=2
print(pow(num,power))
#max() return large number
num=34
power=10
print(max(num,power))
#min() return minimum value
print(min(num,power))
#round() rounding the number
num=34.7
print(round(num))
#######
#for some functions ue need to import specific module
#######
#module is a group of function
from math import *
#sqrt() for square root
num=36
print(sqrt(num))
#floor() changes the decimal value to it`s lowest integer
num=36.5
print(floor(num))
def myfunction():
print("Piyush Anand")
myfunction()
#passing parameters
'''def myfunction(num1,num2):
sum=num1+num2
print(sum)
myfunction(23,27)'''
name=input("enter your name : ")
print(name)
#if else,elif
num=5
if num==10:
print("the number is equal to 10")
print("anand")
#print("piyush")
elif num==5: #for multiple conditions
print("number is 11")
else:
print("not 10")
#for loop
list=[12,13,14,15]
for getList in list:
print(getList)
#while loop is used when we have huge data in data base
num=0
while num<100:
num+=1
print(num)
#used to import one file to another
import externalfile
externalfile .myfunction()
print()
#created by user it self
def myfunction():
print("Piyush Anand")
myfunction()
#passing parameters
def myfunction(num1,num2):
sum=num1+num2
print(sum)
myfunction(23,27)
_piyush=10
piyush=20
print(piyush)
print(_piyush)
#string use " "
name="piyush"
print(name)
#float
piyush=34.5
print(piyush)
#set = unordered data and can store multiple values
set={34,35,"piyush"}
print(set)
#"list" in python (in "array" we can store values of same data type and in "list" we can store values of different data type)
list=["piyush",24,"anand","ok"]
print(list)
print(list[1]) # for calling through index
print(list[1],list[3])
print(list[1:3]) #print all the elements from index 1 to index 3
#list function
list=["piyush","anand","deepak","anand"]
print(list)
#append
list.append("ok") #append or add the element in the end of the list
print(list)
#insert
#list.insert(1,5) #insert value at specific index
print(list)
#remove
list.remove("piyush")
print(list)
#pop
list.pop() #removes the last element
print(list)
#sort (only for same type)
list.sort() #arrange the list into sorted list
print(list)
#reverse
list.reverse() #reverses the index
print(list)
#extend
list2=[10,20,30,40]
list.extend(list2)
print(list)
#copy
list3=[]
list3=list.copy()
print(list)
print(list3)
#clear
list.clear()
print(list)
#2-D list
list2d=[
[21,22,23,24],
[31,32,33,34],
#can be more
]
print(list2d[0][2])
#tuples
#tuple is same like list but once we use it we can`t change any index value
tuple=("piyush","anand")
print(tuple)
print(tuple[1])
#changing the element or index value is not possible
#tuple[1]="deepak"
#print(tuple[1])
#error
#tuple is used very less for protection
#dictionaries
months={
"j":"january",
"f":"february",
"m":"march"
}
print(months.get("f"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment