1. Home
  2. Data Science
  3. Python
  4. What does the 'walrus operator' (:=), added in Python 3.8…

Added 2 Nov 2026

What does the 'walrus operator' (:=), added in Python 3.8, do?

  1. Assigns a value inside an expression Correct answer
  2. Compares two values for identity
  3. Swaps the values of two variables
  4. Declares a constant that cannot change

Correct answer

A. Assigns a value inside an expression

20 views

MCQSEXAM

Explanation

Assignment expressions allow code such as while (line := f.readline()): or if (n := len(data)) > 10:, which avoids calling a function twice.

Reference

Asked in: NTS, Python Developer Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs