Python Lab Work 25_august_2022
"""
Lab Work: Python
Lists:
Indexed,ordered,mutable,declared with [],can have elements of any datatype
To add an element to the list use "append" function
mylist.append("mango")
print(mylist)
appened() to add at the end
insert() to add at any Index
extend() to extend another list at the end
+ operator--> to add one ist with other
mylist.pop()
print(mylist)
mylist.remove("apple")
print(mylist)
To find the length of a list use "len" function
print(len(mylist))
"""
def list_manip(ls1):
ls1=ls1+[5,6,7,8]
def decor_print(func):
def inner_func(str):
return str+"-->"
return inner_func
@decor_print
def myPrint(str):
return str
def main():
# ls=[*(input("Enter the elements for the list").split())]
# ls1=[print(elem,end=" ") for elem in sorted(ls)]
# print(end="\n")
# print(myPrint("This is a string!"))
pass
if __name__=="__main__":
main()
''' To show that variables get new reference every time we make changes to them'''
ls2=[1,2,3,4]
ls3=ls2
# list_manip(ls2)
print(myPrint("Before manip id of ls2"),id(ls2))
ls2=ls2+[5,6,7,8]
print(myPrint("ls3 is"),*ls3)
print(myPrint("id of ls3 is"),id(ls3))
print(myPrint("ls2 is"),*ls2)
print(myPrint("id of ls2 is"),id(ls2))
print(ls4
Comments
Post a Comment