CompTIA PenTest+ (PT0-002) — Question 150

Which of the following expressions in Python increase a variable val by one? (Choose two.)

Answer options

Correct answer: C, F

Explanation

The correct answers are C and F because 'val=(val+1)' explicitly adds 1 to val and assigns it back, while 'val+=1' is a shorthand operator that also increments val by one. The other options are not valid in Python; val++ and ++val are not supported, and val=val++ does not work as intended due to the way Python handles expressions.