Python Identifiers:
programming වලදී යම්කිසි object එකක් හැඳින්වීමට යොදාගන්නා නමක් පොදුවේ
Identifier එකක් ලෙස හඳුන්වයි.මෙය variable එකක් function එකක් class එකක් හෝ object එකක් විය හැකිය.මේවාට නම් ලබාදීමේදී අපට කැමති නම් ලබාදිය නොහැකි අතර ඒ සඳහා නීති මාලාවක් පවතියි.ඒවා පහත ලෙස වෙයි
Identifier එකක් ලෙස හඳුන්වයි.මෙය variable එකක් function එකක් class එකක් හෝ object එකක් විය හැකිය.මේවාට නම් ලබාදීමේදී අපට කැමති නම් ලබාදිය නොහැකි අතර ඒ සඳහා නීති මාලාවක් පවතියි.ඒවා පහත ලෙස වෙයි
- identifier එකක් ආරම්භ කළ යුත්තේ ඉංග්රීසි capital (A-Z) අකුරකින් simple (a-z) අකුරකින් හෝ underscore(_) එක මගින් පමණි වෙනත් කිසිඳු character එකකින් ආරම්භ කළ නොහැක.
- එක අකුරක් පමණක් වුවද identifier එකට ප්රමාණවත් වෙයි.තවත් අකුරු යොදන්නේ නම් ඒ සඳහා අකුරු underscore එක මෙන්ම 0 සිට 9 දක්වා වූ ඕනෑම ඉලක්කමක් හෝ ඉලක්කම් කිහිපයක් වුවද ඇතුලත් කල හැක.
- පෙර කී අකුරු හා symbols හැරුණු විට වෙනත් කිසිම character එකක් identifiers හැදින්වීමට යොදාගත නොහැක.
identifiers නම් කිරීමේදී බලපාන තවත් නීති.
- class name එකක පළමු අකුර capital විය යුතු අතර අනෙක් සියළුම අකුරු simple විය යුතුය.
- identifier එකක් underscore එකකින් ආරම්භ කරයිනම් එය private identifier එකක් ලෙස සලකයි.
- identifier එකක් underscore දෙකකින් ආරම්භ කරයිනම් එය strongly private identifier එකක් ලෙස හඳුන්වයි.
පහත දැක්වෙන්නේ එම වචනයි.
and | exec | not |
assert | finally | or |
break | for | pass |
class | from | |
continue | global | raise |
def | if | return |
del | import | try |
elif | in | while |
else | is | with |
except | lambda | yield |
Lines and Indentation:
python වල code blocks වෙන් කිරීමට වරහන් හෝ කමා භාවිතා නොකරයි.එම සියල්ල වෙන් කිරීම indentation වලින් සිදුකරන අතර එම නිසා නිවැරදිව indentation තැබීම ඉතා වැදගත් වෙයි.
එකම කොටසට අයිතිවෙන හැම code line එකකටම සමාන indentation එකක් තිබිය යුතුය.
උදා;
if True: print "True" else: print "False"
මෙය නිවැරදිය.
if True: print "Answer" print "True" else: print "Answer" print "False"
නමුත් ඉහත else එක යටතේ ඇති code lines දෙකෙහි indentation දෙක එකිනෙකට වෙනස් නිසා error එකක් පෙන්වයි.කෙසේ වෙතත් IDLE එක භාවිතයේදී එය නිවැරදි තැනට curser එක auto යොමු කරන නිසා ඒ ගැන වැඩි වශයෙන් බියවිය යුතු නැත.
Quotation in Python:
python වල වචන වාක්ය ආදී strings දැක්වීමේදී single quotation (') එක හෝ double quotation (") එක යන දෙකෙන් ඕනෑම එකක් භාවිතා කල හැකි අතර මේ දෙකෙන් එකක් හෝ නොදමයි නම් error එකක් පෙන්වයි.
word = 'word' sentence = "This is a sentence." paragraph = """This is a paragraph. It is made up of multiple lines and sentences."""
Comments in Python:
මෙහි ඇතුලත් වන්නේ single line comments පමණි. comment කල යුතු හැම වාක්යයක් ඉදිරියෙන්ම # ලකුණ යෙදිය යුතුය.
#!/usr/bin/python # First comment print "Hello, Python!"; # second comment
This will produce the following result:
Hello, Python!
A comment may be on the same line after a statement or expression:
name = "Madisetti" # This is again comment
You can comment multiple lines as follows:
# This is a comment. # This is a comment, too. # This is a comment, too. # I said that already.
pattay aa...digatama demu..
ReplyDeletethanx
Delete