Adsense

OUO Banner

Latest Posts

Python3 Lesson 2


Lesson 1  မၾကည့္ရေသးသူမွာ ဒီစာေၾကာင္းကို ႏွိပ္ပါ


.
Python Programming
Commands and Functions

Program ေတြကို function ေတြ အမ်ားႀကီးနဲ႔ တည္ေဆာက္ထားၾကပါတယ္။
အေျခခံအားျဖင့္ေတာ့ function ဆိုတာ  လုပ္ေဆာင္ႏိုင္တဲ့ instruction ေတြကို စုစည္းထားျခင္းပဲ ျဖစ္ပါတယ္။
နမူနာအေနနဲ႔ print function ေလးကို ၾကည့္ၾကည့္ပါ။
(Python 3 ကိုသာ ဆက္လက္အသံုးျပဳသြားမွာမို႔ IDLE 3 ကေနပဲ စမ္းသပ္ၾကည့္ပါ။)

   print ("Hello World")
ဒီေနရာမွာ enter ဆင္းလိုက္တာနဲ႔ Hello World ဆိုတာပဲ ေပၚလာမွာျဖစ္ပါတယ္။ ဒါကေတာ့ သိျပီးသားျဖစ္ပါတယ္။
ေျပာစရာလိုေနတာက အဲသည္  command လိုင္းကေလးမွာ ျပန္ၾကည့္ရေအာင္။
ကြန္ပ်ဴတာကေန စာသားေတြ ထုတ္ေပးႏိုင္ေစမယ့္ စကားလံုးျဖစ္တဲ့ print သည္ function ျဖစ္ျပီး Hello World ဆိုတာကေတာ့ ကြ်န္ေတာ္တို႔ရဲ႕  parameter ျဖစ္ပါတယ္။


Python Data Types
Python မွာ native datatypes ေတြ ရွိပါတယ္။ အေရးႀကီးတာေလးေတြကိုပဲ နမူနာ ေဖာ္ျပလိုက္ပါတယ္။

1. Booleans (True or False)
2. Number int(1,2,3,...), float(1.0,1.1,...), fraction(1/2, 2/3,...) ကိန္းျပည့္၊ ဒသမကိန္း၊ အပိုင္းကိန္းေတြအျပင္ ရႈပ္ေထြးတဲ့ ကိန္းတြဲအစပ္ေတြပါ ပါဝင္ႏိုင္ပါတယ္။
3. Strings Strings are sequences of unicode characters. ကိုယ္ေပးခ်င္တဲ့ message, ကိုယ္ေဖာ္ျပခ်င္တဲ့ စာသားေတြကို strings အေနနဲ႔ ေဖာ္ျပႏိုင္ျပီးေတာ့ Python မွာ
Strings ေတြကို စာလံုး အစိမ္းေရာင္နဲ႔ ေဖာ္ျပပါတယ္။ မိမိ ေဖာ္ျပခ်င္တဲ့စာကို ေရးႏိုင္တဲ့ေနရာေပါ့။
4. Bytes and byte arrays မွာေတာ့  ဥပမာေျပာရရင္ jpeg image file  ေတြကိုပဲ ျပရပါမယ္။
5. Lists Lists are ordered, immutable sequences of values တဲ့။ သူ႔ဖြင့္ဆိုခ်က္က ရွင္းလင္းျပည့္စံုတာမို႔ ျမန္မာလို မေဖာ္ျပေတာ့ပါဘူး။
6. Dictionaries Dictionary ဆိုတာကို အားလံုးသိၾကပါတယ္။ Key နဲ႔  value ေတြကို အတြဲလိုက္ ယွဥ္တြဲေဖာ္ျပခ်က္ေပါင္းမ်ားစြာကို သိုေလွာင္ထားတဲ့ အရာေပါ့။
အေရးပါတဲ့ ေဒတာပံုစံေတြကေတာ့ ဒီ ၆မ်ိဳး ျဖစ္ပါတယ္။


Objects
Programming languages ေတြ မ်ားစြာရွိသကဲ့သို႔  Object ကို ဖြင့္ဆိုရွင္းျပပံုခ်င္းလည္း မတူညီဘဲ နည္းလမ္းမ်ားစြာ ကြဲျပားပါတယ္။ အခ်ိဳ႕က Object ေတြမွာ attributes နဲ႔ methods ေတြ ရွိကို ရွိရမယ္။
ဒါေၾကာင့္ Object ဆိုတာ အဲသည္ attributes နဲ႔ methods ေတြ ရွိေနတဲ့ အရာေပါ့။ ဒီလိုေျပာၾကပါတယ္။
အခ်ိဳ႕ကေတာ့ All objcets are subclassable. ပါတဲ့။ Python မွာေတာ့ Object ဆိုတာ broader ေပါ့.
 အခ်ိဳ႕ေသာ Objcet ေတြမွာ attributes နဲ႔ methods ေတြ တစ္ခုမွ မပါတတ္ၾကပါဘူး။ ဒါေပမယ့္ သူတို႔ကို ဖန္တီးႏိုင္ၾကပါတယ္။ ေနာက္ျပီး objects တိုင္းဟာလည္း subclassable မျဖစ္ပါ။
သို႔ေသာ္လည္း variable or argument to a function ျဖစ္တဲ့အရာတိုင္းဟာ object ျဖစ္ပါတယ္။


Indenting Code
Code blocks ေတြဟာ Python program ရဲ႕ အစိတ္အပိုင္းတစ္ခု ျဖစ္ပါတယ္။
Code blocks imply functions, if statement, for loops, while loops, ...

 lesson movie 1 ကို ၾကည့္ပါ။
ဆက္မဖတ္ပါနဲ႔ဦး .................



...........................
Python Programming
.
Example Program

#enter name
name = input("What is your name?")
print ("Hello, " + name + "!")

#enter age
age = input("How old are you?")
print ("That's great, " + name + "!")

#Asking temperature outside
temperature = float(input("What is the temperature outside, " + name + "?"))
if temperature > 70:
print ("Weather is so hot. Please, wear shorts")
print ("Enjoy your day, " + name + "!")
else:
print ("Wear long pants, " + name + "!")
print ("Get some exercise outside")

အထက္ပါ program ကေလးကို idle3 အသံုးျပဳျပီး နမူနာ ေရးျပပါ့မယ္။
Lesson movie 2 မွာ ရွင္းျပထားပါတယ္ခင္ဗ်


To be continued ..........
Lesson 3 ၾကည့္ရန္ ဒီစာေၾကာင္းကိုႏွိပ္ပါ


Thanks


Khit Minnyo

No comments