Python ရဲ့ဒေတာအမျိုးအစားများနှင့်အမျိုးအစားပြောင်းလဲမှုများကိုမည်သို့ပြုလုပ်ရမည်ကိုမိတ်ဆက်ပေးသည်။
ကျနော်တို့ Python မှာ variable တွေကိုဖန်တီးသို့မဟုတ်ကြေငြာသောအခါ, variable တွေကိုကွဲပြားခြားနားသောဒေတာအမျိုးအစားများကိုကိုင်ထားနိုင်ပါတယ်။
Python တွင်အောက်ပါ built-in ဒေတာအမျိုးအစားများရှိသည်။
str
ကျွန်ုပ်တို့က a ကိုကြေငြာလိုသည့်အခါအချက်အလက်အမျိုးအစားကိုအသုံးပြုသည် ကြိုး variable ။
ဥပမာ -
x = 'some string' y = str('another string')
ကိန်းဂဏန်း variable များကိုကျွန်ုပ်တို့ဖန်တီးလိုပါက int
, float
သို့မဟုတ် complex
။
ဥပမာ -
//int a = 5 b = int(5) //float c = 5.5 d = float(5.5) //complex e = 1j f = complex(1j)
sequence အမျိုးအစား variable များကိုဖန်တီးရန်ကျွန်ုပ်တို့သည် _ _ _ _ _ ကိုအသုံးပြုသည် သို့မဟုတ် list
။
tuple
အမိန့်နှင့်ပြောင်းလဲသောစုဆောင်းမှုဖြစ်ပါတယ်။ ထပ်တူများကိုအဖွဲ့ဝင်ခွင့်ပြုသည်။list
အမိန့်များနှင့်မပြောင်းနိုင်သောစုဆောင်းမှုဖြစ်ပါတယ်။ ထပ်တူများကိုအဖွဲ့ဝင်ခွင့်ပြုသည်။ဥပမာ -
tuple
မြေပုံသို့မဟုတ်အဘိဓာန်ကိုဖန်တီးရန်ကျွန်ုပ်တို့သည် _ _ _ _ ကိုအသုံးပြုသည်။
TO သို့ အဘိဓါန် ပြောင်းလဲခြင်းနှင့်ရည်ညွှန်းခြင်းပြုလုပ်ထားသောစုဆောင်းမှုတစ်ခုဖြစ်သည်။ အဆိုပါဒေတာ key ကိုတန်ဖိုးအားလုံးဖြစ်ကြသည်။
ဥပမာ -
//list colors = ['red', 'green', 'blue'] colors_list = list(('red', 'green', 'blue')) //tuple fruits = ('apple', 'orange', 'banana') fruits_tuple = list(('apple', 'orange', 'banana'))
A dict
unordered နှင့် indexed မဟုတ်သောစုဆောင်းမှုတစ်ခုဖြစ်သည်။
အစုတခုကိုဖန်တီးရန်ကျွန်ုပ်တို့သည် _ _ _ _ _ ကိုအသုံးပြုသည်။
ဥပမာ -
people = {'name': 'John', 'age': '45'} people_dict = dict(name='John', age=45)
set
သော့ချက်စာလုံးကို boolean data type နှင့်အတူ variable တွေကိုဖန်တီးရန်အသုံးပြုသည်။
set
Binary data အမျိုးအစားများကိုအောက်ပါအတိုင်းဖန်တီးနိုင်သည် -
status_codes = {'200', '300', '400', '500'} status_codes = set(('200', '300', '400', '500'))
Variable အမျိုးအစားတစ်ခုရဖို့အတွက် _ _ _ _ အတွင်းက variable ကိုထုပ်လိုက်တယ် function ကို။
ဥပမာ:
bool
ရလဒ် -
is_valid = False valid = bool(is_valid)
Python ကဒေတာအမျိုးအစားတစ်ခုကိုအခြားတစ်ခုသို့တိုက်ရိုက်ပြောင်းလဲရန်အမျိုးအစားပြောင်းလဲခြင်းလုပ်ဆောင်ချက်များကိုသတ်မှတ်သည်။ ၎င်းသည်အတော်လေးအသုံးဝင်သည်။
အောက်တွင်ဥပမာအချို့ကိုဖော်ပြထားသည် -
//bytes a = b'some_text' b = bytes(5) //bytearray c = bytearray(3)
ရလဒ် -
type()
colors = ['red', 'green', 'blue'] colors_list = list(('red', 'green', 'blue')) print(type(colors_list)) print(colors_list) fruits = ('apple', 'orange', 'banana') fruits_tuple = tuple(('apple', 'orange', 'banana')) print(type(fruits_tuple)) print(fruits_tuple)
ရလဒ် -
['red', 'green', 'blue'] ('apple', 'orange', 'banana')
x = 5 y = float(x) print(y)
ရလဒ် -
5.0
x = 5.0 y = int(x) print(y)
ရလဒ် -
5
s = 'devqa' t = list(s) print(t)
ရလဒ် -
['d', 'e', 'v', 'q', 'a']