Test Index

CBSE Class 12 Computer Science 2026 Paper Set 4 Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 23 of 37
Marks: +1, -0
Write a Python statement to perform the following tasks : (USE BUILT_IN FUNCTIONS / METHODS ONLY)
(i) To create a new list L1 containing the elements of list L arranged in ascending order, without modifying list L.
(ii) A statement to check whether the given character, ch is an alphabet or a number.
Solution:  
(i)
L1 = sorted(L)
The built-in function sorted() returns a new sorted list and leaves L unchanged. (L.sort() would sort L itself and return None, so it does not suit.)
L = [5, 2, 9, 1]
L1 = sorted(L)
print(L) # [5, 2, 9, 1]
print(L1) # [1, 2, 5, 9]
(ii)
ch.isalnum()
isalnum() returns True if the character is an alphabet or a digit, otherwise False. Equivalent: ch.isalpha() or ch.isdigit().
print('a'.isalnum())    # True  (alphabet)
print('7'.isalnum()) # True (number)
print('#'.isalnum()) # False
© examsnet.com
Advertisements
Go to Question: