ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 48 - PT0-002 discussion

Report
Export

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

A.
val++
Answers
A.
val++
B.
+val
Answers
B.
+val
C.
val=(val+1)
Answers
C.
val=(val+1)
D.
++val
Answers
D.
++val
E.
val=val++
Answers
E.
val=val++
F.
val+=1
Answers
F.
val+=1
Suggested answer: C, F

Explanation:

In Python, there are two ways to increase a variable by one: using the assignment operator (=) with an arithmetic expression, or using the augmented assignment operator (+=). The expressions val=(val+1) and val+=1 both achieve this goal. The expressions val++ and ++val are not valid in Python, as there is no increment operator. The expressions +val and val=val++ do not change the value of val2.

https://pythonguides.com/increment-and-decrement-operators-in-python/

asked 02/10/2024
Mohammad Wahid
46 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first