Python Data အမျိုးအစားများနှင့်အမျိုးအစားကူးပြောင်းခြင်း

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



Python အချက်အလက်အမျိုးအစားများ

ကျနော်တို့ Python မှာ variable တွေကိုဖန်တီးသို့မဟုတ်ကြေငြာသောအခါ, variable တွေကိုကွဲပြားခြားနားသောဒေတာအမျိုးအစားများကိုကိုင်ထားနိုင်ပါတယ်။

Python တွင်အောက်ပါ built-in ဒေတာအမျိုးအစားများရှိသည်။


  • int, float, ရှုပ်ထွေးသော
  • စာရင်း tuple
  • dict
  • အစုံ
  • bool
  • byte, bytearray

စာသားအမျိုးအစား: str

str ကျွန်ုပ်တို့က a ကိုကြေငြာလိုသည့်အခါအချက်အလက်အမျိုးအစားကိုအသုံးပြုသည် ကြိုး variable ။

ဥပမာ -


x = 'some string' y = str('another string')

ဂဏန်းအမျိုးအစား: int, float, ရှုပ်ထွေးသော

ကိန်းဂဏန်း variable များကိုကျွန်ုပ်တို့ဖန်တီးလိုပါက int, float သို့မဟုတ် complex

ဥပမာ -

//int a = 5 b = int(5) //float c = 5.5 d = float(5.5) //complex e = 1j f = complex(1j)

အစီအစဉ်အမျိုးအစား: စာရင်း၊ tuple

sequence အမျိုးအစား variable များကိုဖန်တီးရန်ကျွန်ုပ်တို့သည် _ _ _ _ _ ကိုအသုံးပြုသည် သို့မဟုတ် list

  • A tuple အမိန့်နှင့်ပြောင်းလဲသောစုဆောင်းမှုဖြစ်ပါတယ်။ ထပ်တူများကိုအဖွဲ့ဝင်ခွင့်ပြုသည်။
  • A list အမိန့်များနှင့်မပြောင်းနိုင်သောစုဆောင်းမှုဖြစ်ပါတယ်။ ထပ်တူများကိုအဖွဲ့ဝင်ခွင့်ပြုသည်။

ဥပမာ -


tuple

မြေပုံအမျိုးအစား: dict

မြေပုံသို့မဟုတ်အဘိဓာန်ကိုဖန်တီးရန်ကျွန်ုပ်တို့သည် _ _ _ _ ကိုအသုံးပြုသည်။

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)

Boolean အမျိုးအစား: bool

set သော့ချက်စာလုံးကို boolean data type နှင့်အတူ variable တွေကိုဖန်တီးရန်အသုံးပြုသည်။

set

Binary အမျိုးအစား: byte, bytearray

Binary data အမျိုးအစားများကိုအောက်ပါအတိုင်းဖန်တီးနိုင်သည် -


status_codes = {'200', '300', '400', '500'} status_codes = set(('200', '300', '400', '500'))

Variable အမျိုးအစားကိုဘယ်လိုရနိုင်မလဲ

Variable အမျိုးအစားတစ်ခုရဖို့အတွက် _ _ _ _ အတွင်းက variable ကိုထုပ်လိုက်တယ် function ကို။

ဥပမာ:

bool

ရလဒ် -

is_valid = False valid = bool(is_valid)

Python ဒေတာအမျိုးအစားပြောင်းလဲခြင်း

Python ကဒေတာအမျိုးအစားတစ်ခုကိုအခြားတစ်ခုသို့တိုက်ရိုက်ပြောင်းလဲရန်အမျိုးအစားပြောင်းလဲခြင်းလုပ်ဆောင်ချက်များကိုသတ်မှတ်သည်။ ၎င်းသည်အတော်လေးအသုံးဝင်သည်။


အောက်တွင်ဥပမာအချို့ကိုဖော်ပြထားသည် -

int မှ float သို့ပြောင်းပါ

//bytes a = b'some_text' b = bytes(5) //bytearray c = bytearray(3)

ရလဒ် -

type()

float မှစ။ int သို့ပြောင်း

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')

string ကနေစာရင်းသို့ပြောင်းပါ

x = 5 y = float(x) print(y)

ရလဒ် -

5.0

string ကနေ tuple သို့ပြောင်းလဲ

x = 5.0 y = int(x) print(y)

ရလဒ် -

5

string မှစ။ ထားရန်ပြောင်းလဲ

s = 'devqa' t = list(s) print(t)

ရလဒ် -

['d', 'e', 'v', 'q', 'a']

အယ်ဒီတာရဲ့ရွေးချယ်မှု

စိတ်ဝင်စားစရာဆောင်းပါးများ