match..case statement in PYTHON The latest Python starting from Python 3.10, a match..case structure has been introduced as an alternative to switch..case in other languages. Syntax: match term : case pattern - 1 : action - 1 case pattern - 2 : action - 2 case pattern - 3 : action - 3 .... .... case pattern-n: action-n case _ : default-action statement - x If any pattern (pattern-1, pattern-2, pattern-3, ..., pattern-n) starting from pattern-1 is matched with the term, then the corresponding action will be performed, and after that, the statement following the match..case will execute. i.e., statement-x. If none of the patterns match, case ...
What is the output of the following Python code snippet? def fun(a): a.append(100) print(a) a=[10,20,30] print("Before calling function fun, the value of a=",a) fun(a) print("After calling function fun, the value of a=",a) OUTPUT Before calling function fun, the value of a= [10, 20, 30] [10, 20, 30, 100] After calling function fun, the value of a= [10, 20, 30, 100] Explanation: Here the list a is passed as a parameter to the function namely fun . Since the list is a mutable type, by default it is passed as a reference. So any changes to the parameter a within the function fun will affect the original list a . So the value of the list after function call is [10,20,30,100].
What is the output of the following code snippet? #include <stdio.h> void main(){ printf("%d",(12%2)); } Output: 0 Explanation: % is the mod operator in c, which is used to find remainder of an integer division.
Comments
Post a Comment