DEV Community

Manimegalai S
Manimegalai S

Posted on

Python learning

  • Today the concept learnt

Code snippet

packages = ['Letter', 'Box', 'Parcel']
print(packages)
print(type(packages))
print(packages[0])
print(type(packages[0]))


#Appending the item in list
packages.append('special delivery')
print(packages)

#Appending the item in specific place in list
packages.insert(2, 'Glass bottle')
print(packages)

#Appending the number in last place as a string
packages.append(3)
print(packages, packages[5], type(packages[5]))


#take last package out using pop. Last item will be out and package size will be reduced
last_package = packages.pop(-2)
print(last_package, type(last_package))
print(packages)

#sorting of packages of same instance
#packages.sort()
#print(packages)  # this will through the error as int and str instances are present
last_package = packages.pop()
packages.sort()
print(packages)

#Reversing the package
packages.append(4)
print(packages.reverse())   # returning None
print(packages)


num_package = [1,2,3,4,5,6]
last_num_package = num_package.pop()
print(last_num_package, type(last_num_package))
print(num_package, type(num_package))

num_package = [1,2,3,4,5,6]
num_package.append({7,8,9})
print(num_package)
print(num_package[-1], type(num_package[-1]))

#Different packages


Enter fullscreen mode Exit fullscreen mode

Top comments (0)