Computer Science, asked by manojbhise8818, 10 months ago

What gets printed ?
x = 1
y = "2"
z = 3
sum = 0
for i in (x,y,z):
if isinstance(i, int):
sum + = i
print sum

Answers

Answered by rehmatsara
0

Answer:

Mainu chhad aajkal kisda ae tu

Answered by mariospartan
1

4 will be printed

Explanation:

I am considering the given snippet, assuming x,y,z is already assumed.

x = 1 - consider to be an integer

y= "2" - will be string

z =3 - will once again be an integer based on the value assigned to the variable

isInstance(): This method checks whether both the variable belong to the same  type / class.

for loop gets the value one by one as follows:

1.  i = 1 so its integer and isinstance() will return true so, sum 0 + 1 = 1

2. i = "2" so, isInstance() will return false since string is compared with int, so its skips the current iteration

3. i = 3, so isInstance() will return true since both are integer, sum = 1 + 3 = 4

So the output 4 will be printed.

But to consider deeper, isinstance() has improper casing, so it might return error.

To Know More:

https://brainly.in/question/7663699

What are data types in python and why are they important?

https://brainly.in/question/1289934

What is the difference between instanceof and isinstance?

Similar questions