Python တွင် dictionary အတွင်း element ရှိမရှိ စစ်ဆေးခြင်း

Dictionary အတွင်း key တစ်ခုရှိမရှိကို in operator ဖြင့်စစ်ဆေးနိုင်ပြီး မရှိကြောင်းကိုမူ not in ဖြင့် စစ်ဆေးနိုင်ပါသည်။

လက်တွေ့စမ်းကြည့်ပါမည်။ ကျွန်ုပ်တို့တွင် အောက်ပါ dictionary ရှိသည်ဆိုပါစို့။

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

Dictionary အတွင်း key 'a' ပါသော element ရှိမရှိ စစ်ဆေးကြည့်ပါမည်။

pythonprint('a' in dct) # True ကိုထုတ်ပြမည်

Dictionary အတွင်း key 'x' ပါသော element မရှိကြောင်း စစ်ဆေးကြည့်ပါမည်။

pythonprint('x' not in dct) # True ကိုထုတ်ပြမည်
Задание 1

Dictionary ပေးထားသည်။

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

၄င်းအတွင်း key 'w' ပါသော element ရှိမရှိ စစ်ဆေးပါ။

Задание 2

အောက်ပါ code ပေးထားသည်။

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

print('x' in dct)

Console တွင် မည်သည်ကို ထုတ်ပြမည်နည်း။

Задание 3

အောက်ပါ code ပေးထားသည်။

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

print('x' not in dct)

Console တွင် မည်သည်ကို ထုတ်ပြမည်နည်း။

Задание 4

အောက်ပါ code ပေးထားသည်။

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

print(3 in dct)

Console တွင် မည်သည်ကို ထုတ်ပြမည်နည်း။