Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Simple list operations in Python

16 views
License: OTHER
ubuntu2204
Kernel: Python 3 (Anaconda 2022)
list=[1,"hello",[2,3,4,5],4,5] print(list) print(list[1])
[1, 'hello', [2, 3, 4, 5], 4, 5] hello
list.append(34) list
[1, 'hello', 45, 45, [2, 3, 4, 5], 4, 5, 34]
list.remove(45) list
[1, 'hello', 'hi', 45, [2, 3, 4, 5], 4, 34]
list.insert(2,"hi") list
[1, 'hello', 'hi', 45, 45, [2, 3, 4, 5], 4, 34]
x=[5,12,45,32,12] print(min(x)) print(max(x))
5 45
list
[1, 'hello', 'hi', 45, [2, 3, 4, 5], 4, 34]
list.insert(3,[2,6,7]) list
[1, 'hello', 'hi', [2, 6, 7], 45, [2, 3, 4, 5], 4, 34]
value = "hello" if value in list: print("True") else: print("False")
True
value = "hello" if value not in list: print("True") else: print("False")
False
list=[2,3,5,6,7] list1=[56,78,34,21] l3=list+list1 l3
[2, 3, 5, 6, 7, 56, 78, 34, 21]
l3[::-1]
[21, 34, 78, 56, 7, 6, 5, 3, 2]
cubes=[i**3 for i in range(10)] cubes
[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]
def var(): print("varshini") var()
varshini