- 2
Do anyone know what is "?"
Fill in the blanks to print the first element of the list, if it contains even number of elements. list = [1, 2, 3, 4] if ? (list) % 2 == 0: print(list[0])
4 Answers
+ 8
Looks like a quiz from python course.
Hint:
You can think about any list function to get the total number of elements in a list.
Btw, you can check the comments section if you can't understand any quizzes
+ 1
Your code example is in Python
Python ternary operator isn't using ? or :
0
Module quiz?
Which module / chapter?
I don't remember this one.
- 1
? Is a ternary operator....it executes like this...
Variable= expression1 ? expression2 : expression 3
Or in layman terms-
If(expression1)
{
variable=expression2;
}
else
{
variable=expression3;
}
Here,expression1 is the condition to be evaluated.If the condition (expression1) is true then expression2 will be executed and if expression1 ks false then expression3 will be executed..