What will be the output of the following Python code snippet?
print(''.isdigit())
print('abc'.islower())
print('a@ 1,'.islower())
print('11'.isnumeric())
print('1.1'.isnumeric())
print('HelloWorld'.istitle())
print('Hello World'.istitle())
What will be the output of the following Python code?
print('Hello!2@#World'.istitle())
print('1Rn@'.lower())
print('xyyzxxyxyy'.lstrip('xyy'))
print('xyxxyyzxxy'.lstrip('xyy'))
print('abcdef'.partition('cd'))
print('abcdefcdgh'.partition('cd'))
print('abcd'.partition('cd'))
print('cd'.partition('cd'))
print('abef'.partition('cd'))
print('abcdef12'.replace('cd', '12'))
print('abef'.replace('cd', '12'))
print('abcefd'.replace('cd', '12'))
print('xyyxyyxyxyxxy'.replace('xy', '12', 100))
print('abcdefcdghcd'.split('cd'))
print('abcdefcdghcd'.split('cd', 0))
print('abcdefcdghcd'.split('cd', -1))
print('abcdefcdghcd'.split('cd', 2))
print('Ab!2'.swapcase())
print('ab cd ef'.title())
print('ab cd-ef'.title())
What is the output of the following code?
list1=[2, 33, 222, 14, 25] print(list1[ : -1 ])
names = ['Amir', 'Bear', 'Charlton', 'Daman'] print(names[-1][-1])
list1 = [11, 2, 23] list2 = [11, 2, 2] print(list1 < list2)
print("Welcome to Python".split())
mylist=list("a#b#c#d".split('#')) print(mylist)
myList = [1, 5, 5, 5, 5, 1] max = myList[0] indexOfMax = 0 for i in range(1, len(myList)): if myList[i] > max: max = myList[i] indexOfMax = i print(indexOfMax)
myList = [1, 2, 3, 4, 5, 6] for i in range(1, 6): myList[i - 1] = myList[i] for i in range(0, 6): print(myList[i], end = " ")
list1 = [1, 3] list2 = list1 list1[0] = 4 print(list2)
def f(values): values[0] = 44 v = [1, 2, 3] f(v) print(v)
values = [[3, 4, 5, 1], [33, 6, 1, 2]] v = values[0][0] for row in range(0, len(values)): for column in range(0, len(values[row])): if v < values[row][column]: v = values[row][column] print(v)
values = [[3, 4, 5, 1], [33, 6, 1, 2]] v = values[0][0] for lst in values: for element in lst: if v > element: v = element print(v)
values = [[3, 4, 5, 1 ], [33, 6, 1, 2]] for row in values: row.sort() for element in row: print(element, end = " ") print()
matrix = [[1, 2, 3, 4], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]] for i in range(0, 4): print(matrix[i][1], end = " ")
def m(list): v = list[0] for e in list: if v < e: v = e return v values = [[3, 4, 5, 1], [33, 6, 1, 2]] for row in values: print(m(row), end = " ")
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] def ttt(m): v = m[0][0] for row in m: for element in row: if v < element: v = element return v print(ttt(data[0]))
points = [[1, 2], [3, 1.5], [0.5, 0.5]] points.sort() print(points)
a=[10,23,56,[78]] b=list(a) a[3][0]=95 a[1]=34 print(b)
lst=[3,4,6,1,2] lst[1:2]=[7,8] print(lst)
a=[1,2,3] b=a.append(4) print(a) print(b)
a=[13,56,17] a.append([87]) a.extend([45,67]) print(a)
word1="Apple" word2="Apple" list1=[1,2,3] list2=[1,2,3] print(word1 is word2) print(list1 is list2)
def unpack(a,b,c,d): print(a+d) x = [1,2,3,4] unpack(*x)
places = ['Bangalore', 'Mumbai', 'Delhi'] places1 = places places2 = places[:] places1[1]="Pune" places2[2]="Hyderabad" print(places)
a= [1, 2, 3, 4, 5] for i in range(1, 5): a[i-1] = a[i] for i in range(0, 5): print(a[i],end = " ")
a=["Apple","Ball","Cobra"] a.sort(key=len) print(a)
print([i.lower() for i in "HELLO"])
print([i+j for i in "abc" for j in "def"])
print([[i+j for i in "abc"] for j in "def"])
print([if i%2==0: i; else: i+1; for i in range(4)])
l=[1,2,3,4,5] [x&1 for x in l]
l1=[1,2,3] l2=[4,5,6] [x*y for x in l1 for y in l2]
s=["pune", "mumbai", "delhi"] [(w.upper(), len(w)) for w in s]
l1=[10, 20, 30] l2=[-10, -20, -30] l3=[x+y for x, y in zip(l1, l2)] l3
import math [str(round(math.pi)) for i in range (1, 6)]
Read the information given below carefully and write a list comprehension such that the output is: [‘e’, ‘o’]
w="hello" v=('a', 'e', 'i', 'o', 'u')
[ord(ch) for ch in 'abc']
t=32.00 for x in t: print(x)
Write a list comprehension equivalent for the Python code shown below.
for i in range(1, 101): if int(i*0.5)==i*0.5: print(i)
What is the list comprehension equivalent for?
{x : x is a whole number less than 20, x is even} (including zero)
What will be the output of the following Python list comprehension?
[j for i in range(2,8) for j in range(i*2, 50, i)]
l=["good", "oh!", "excellent!", "#450"] [n for n in l if n.isalpha() or n.isdigit()]
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] A[1]