Having an item in a dictionary in Python

You can check the presence of a key in a dictionary using the in operator, and its absence using not in.

Let's see in practice. Let's say we have the following dictionary:

pythondct = {
  'a': 1,
  'b': 2,
  'c': 3
}

Let's check if there is an element with key 'a' in the dictionary:

pythonprint('a' in dct) # True

Let's check that there is no element in the dictionary with the key 'x':

pythonprint('x' not in dct) # True
Задание 1

Given a dictionary:

pythondct = {
  'x': 1,
  'y': 2,
  'z': 3
}

Check if it contains an element with key 'w'.

Задание 2

The following code is given:

pythondct = {
  1: 'x',
  2: 'y',
  3: 'z',
  4: 'w'
}

print('x' in dct)

Tell me what will be output to the console.

Задание 3

The following code is given:

pythondct = {
  1: 'x',
  2: 'y',
  3: 'z',
  4: 'w'
}

print('x' not in dct)

Tell me what will be output to the console.

Задание 4

The following code is given:

pythondct = {
  1: 'x',
  2: 'y',
  3: 'z',
  4: 'w'
}

print(3 in dct)

Tell me what will be output to the console.