0% found this document useful (0 votes)
5 views5 pages

Short Note - Python

The document provides an overview of Python programming concepts, including comments, variables, data types, operators, and control structures such as loops and conditionals. It covers the syntax for single-line and multi-line comments, various data types like integers, floats, and strings, as well as the use of lists, tuples, and dictionaries. Additionally, it discusses the importance of function definitions and file handling in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Short Note - Python

The document provides an overview of Python programming concepts, including comments, variables, data types, operators, and control structures such as loops and conditionals. It covers the syntax for single-line and multi-line comments, various data types like integers, floats, and strings, as well as the use of lists, tuples, and dictionaries. Additionally, it discusses the importance of function definitions and file handling in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

l%uf,aLlrKh

.eg`M úi§fï l%shdj,sfha mshjr Python l%uf,aL NdIdj


1' .eg`Mj úYaf,aIKh lsÍu
2' we,af.dß;u [Link] [Link] ² újrK (Comments)
3' mß.Kl l%uf,aLh ieliSu mß.Kl jevigykl l%shdldÍ;ajh meyeÈ,s
4' l%uf,aLfha fodaI y`ÿkd .ekSu lrk w;r jevigyfka l%shdldÍ;ajhg
5' l%shd;aul lsÍu n,mEula we;s fkdlrhs'
1' single line comments
² we,af.dß;u [Link] [Link] #this is a comment
.eg`Mjla úi`§fï mshjr wkqms<sfj<ska ±laùu
we,af.dß;uhls' 2' multi line comments
ks¾udKh l< yels wdldr 3ls' ''' This is
also a
1' Flow Chart ^.e,Sï igyka& comment'''
2' Pseudo Code ^jHdc fla;&
3' Hand Trace ^yia;dkqf¾Ld& ² úp,H (Variables)
[Link] ;djld,slj .nvd lsÍug Ndú;d fõ
² mß.Kl l%uf,aL ieliSu úp,H kdu$y`ÿkajk f;aÍfï§ my; wdldrhg
we,af.dß;u Ndú;d lr l%shd;aul jk l< hq;=h'
mß.Kl jevigyka ks¾udKh lrhs' 1' há br (_) fyda wl=rlska werôh hq;=h'
2' ixfla; Ndú;d l< fkdyel'
python, C, C#, C++, JAVA (@,#,%,jeks)
3' Case Sensitive fõ'
² .e,Sï igyka (Flow Chart) (Capital/simple fjkiaj y`ÿkd .kS)
we,af.dß;uhlA Ñ;%l$rEmuh wdldrfhka
ksrEmkh lrhs' NdId mßj¾:l uDÿldx.

Ndú;d jk ixfla; ² w¾: úkHdil (Interpretre)


l%uf,aLfha mshjfrka mshjr mßj¾;kh
Python

wdrïNh$wjidkh wdodk$m%;sodk ² iïmdol (Compiler)


iïmQ¾K l%uf,aLhu tljr mßj¾;kh
lrhs'
Pascal
l%shdj,s
f;aÍï o;a; j¾. (Data types)
1' Intergers ^ksÅ,&
mQ¾K ixLHd ksrEmkh lrhs'
.e,Sï ÈYdj iïnkaOl
2' Float ^oYu&
oYu ixLHd ksrEmkh lrhs'
² we,af.dß;u md,k jHqy 3ls'
³ wkql%uh Sequence 3' Boolean ^nQ,Sh [Link]&
mshjr wkqms<sfj<ska .,d hhs' i;H$wi;H nj ksrEmkh lrhs'

³ jrKh ^f;aÍï& Selection


hï mshjrla f;dard f.k bÈßhg hdu

³ mqk¾lrKh Iteration


hï mshjrla f;dard f.k bÈßhg hdu
LASITHA PRASAD
oefkkak ict
[Link] PAGE 1
l%uf,aLlrKh
Operators & Expressions ² a = 10 a>>2
8 4 2 1
1' wxl .Ks;uh (Arithmetic) 1 0 1 0 tkï iEu ìgqjlau ia:dk
2' iyiïnkaê; (Relational/Comparison) folla >> foig .uka lr
3' Assignment 0 0 1 0 ;sfí'
4' ;d¾lsl (Logical) 2
5' ìgq wkqidß; (Bitwise)
6' Membership
7' Identity ² a = 10 a<<2

1' wxl .Ks;uh 32 16 8 4 2 1


² uQ,sl .Ks; l¾u isÿ lrhs' 1 0 1 0
² 4+5=9 tkï iEu ìgqjlau ia:dk
"a" + "b" = "ab" 1 0 1 0
40 folla << foig .uka lr
² +, -, *, **, /, %, // ;sfí'
² 2**2=22=4
² 4/2 = 2.0
² 16%3 = 1 ² 5 & 3 idok wdldrh
² 10//3 = 3 oaúuh lr .kak'
101 & 011
2' iy iïnkaê; 101 AND 011 = 0012 tkï 1
² [Link] ixikaokhg Ndú;d fõ'
² 3<4 True 4' ;d¾lsl
3>4 False Time$False [Link] ,ndf.k tau;
l%shd;aul fõ
² 4==4 True and,or,not
5==4 False a = True
b = False kï
² 4! = 5 True a and b False
4! = 4 False a or b True
not b True
² <, >, <=, >=, ==, != Ndú;d fõ'
5. Membership
3' ìgq wkqidß; o;a; wkql%uhl [Link] ;sfío keoao hkak
² tla tla úp,H j, oaúuh w.h ,ndf.k mÍlaId lsÍu
ìgq wkqidß; ld¾hhka isÿ lr kej; in, not in
mej;s iajrEmfhkau o;a; yrjd m%;sodkh x = [23, 45, 68, 10] #output
lrhs print(45 in x) True
² & - AND ~ Bitwise Invert print (70 not in x) True
| - OR << - Binary Left Shift
^ - XOR >> - Binary Right Shift 6. Identity
úp,H 2l [Link] ikaikaokhla lsÍug
² Bit wise Invert (~) fhdod .kS
X kï úp,Hfha w.h jkqfha is, is not
-(x+1)
~5 kï -(5+1) -6 x=8
y=8
x is y True
x is not y False

LASITHA PRASAD
ict
oefkkak
[Link] PAGE 2
l%uf,aLlrKh
² Assignment List
jákdlula wdfoaY lsÍug Ndú;d fõ' ² mutable fõ'
=, +=, -=, *=, /=, %=, //=, **= ² kej; kej; tlu o;a;h fhÈh yelsh'
x+ = 30 kï thska woyia jkafka" ² ^String" Float" & úúO j¾.fha o;a; ;sìh
x = x + 30 hkakhs' yelsh'
ta wdldrhg by; wfkl=;a ldrlo ² List01=["mom", "dad", "bro"]
l%shd;aul fõ
² fuys§ ia:dkSh [Link] Ndú;d l< yelsfõ'
² list iuÕ Y%s; Ndú;h
o;a; j¾. insert ^index no" item&
,ehsia;=fõ ksYaÑ; ia:dkSh [Link]
String whs;uhla we;=,a lsÍu
² Wvq fldud we;=<; olajhs'
ia:dkSh [Link] Ndú;d l< yelsh' append ^&
x = "Lasitha" whs;uhla ,hsia;=fõ w.g we;=,;a lrhs
L a s i t h a
del listname ['index no']
0 1 2 3 4 5 6
,ehsia;=jl hï ia:dkhl whs;uh tys
-7 -6 -5 -4 -3 -2 -1 index no' Ndú;fhka bj;a lrhs'
remove ^&
print (x [0:6]) #output
Lasith ,ehsia;=fõ jákdlula bj;a lrhs
print (x [-4:-2]) len^&
it
count ^&
² string iu`. reverse ^& ^reverse tlg list tl m%;sOdkh&
+, * , in, not in Ndú;d fõ'
x = "Lasitha" #OUTPUT
x = x + "Prasad" LasithaPrasad Tuple
print (x) ² () Ndú;d fõ'
² immutable fõ'
² string iu`. Ndú; l< yels Y%s; ² úúO j¾.fha o;a; kej; kej; fhÈh yel
upper () - ish¨ wl=re capital lrhs' ² tuple folla tl;= lsÍu l< yels w;r
lower () - ish¨ wl=re simpal lrhs' fjk;a fjkialï l< fkdyel'
count () - hï fldgia fh§ we;s jdr ² Ndú;d l< yels Y%s;
.Kk' len ^tuplename&
len () - È. $wl=re .Kk fiùu' [Link] ^&
split () - fok [Link] u; string fldgia [Link] ()
fjka lsÍu'
Dictionary
jeo.;a lreKq ² {} Ndú;d fõ'
mutable - hï jia;=jla ks¾udKh l< miq tys ² mutable fõ'
w.h fjkia l< yelskï tajd ² key, value hq.< f,i o;a; we;'
mutable fõ' ² úúO j¾.fha o;a; ;sìh yelsh'
imutable - ks¾udKh l< miq w.h fjkia l<
fkdyels kï immutable fõ' ² dic01={"Amila" : "1990", "Janith" : "1957"}

² jákdlula we;=`M lsÍu


dic01 ["Kamal" ] = "1996"
² ish`M o;a; bj;a lsÍu'
[Link]()
² iïmQ¾K dictionary tl bj;a lsÍu

LASITHA PRASAD
ict
oefkkak
[Link]
del dic01
PAGE 3
l%uf,aLlrKh
mqk¾lrKh
m%uqL;djh (precedence) wdldr 2ls'
² m%uqL;djh jevs isg wvq ms<sfj<ska' 1. for loop
² tl fma<sfha we;s tajdh iudk m%uqL;djhla 2. while loop
mj;S
** for Loop
~, +, - mqk¾lrKh jk jdr .Kk ksYaÑ; kï
*, / , %, // Ndú;d fõ'
+, - hï mrdihl fyda ,hsia;=jl Ndú;d l<
>>, << yelsh'
&
^, | mrdihl
<=, <, >, >= Syntax ^ldrl kS;sh&
=, %=, +=, *=, **= wdrïNl w.h lSfhka lSh Gap tlla
o hkak
is, is not,
in, not in for i in range (Start value, stop value, step value);
not, or, and -----------------------------------------------------
wjika w.h
-----------------------------------------------------
l%uf,aL [Link]ï§ fmr fuka md,k jHqy
3la Ndú;d fõ' ,ehsia;=jl
1' wkql%uh (Sequence) Syntax ^ldrl kS;sh&
ms<sfj,ska .,dhdu isÿfõ
^mshjfrka mshjr& for Listname in List:

2' jrKh (Selection) ..................................................................


if, elif, else Ndú;d fõ'

Syntax ^ldrl kS;sh&


if ................................ : while Loop
................................................. mqk¾lrKh jk jdr .Kk ksYaÑ; ke;akï
elif ................................ : Ndú;d fõ'
.................................................. jdr .Kk okafka kï túg o Ndú;d l<
else : yelsh
................................................... Syntax ^ldrl kS;sh&

jeo.;a lreKq while .............................................. :


o;a; wdodkhla ,nd .kakd wdldrh ..............................................
oYu kï" (Float) ..............................................
x=float(input("Enter"))

ksÅ, kï" (interger) Æm iu`. break, continue keywords


x=int(input("Enter"))
break
string kï" (default fõ) mqk¾lrKh ùfï§ hï lreKla i;H ù break
x=input("Enter")) lr ;sfí kï t;kska loop tl wjika ù loop
or fhka msgùu isÿfõ'
x=str(input("Enter"))
;srfha m%o¾Ykh jk hula we;=<;a
lsÍfï§ — ˜ ,l=Kq we;=<; th i`oyka l<
hq;=h'
LASITHA PRASAD
oefkkak ict
[Link] PAGE 4
l%uf,aLlrKh
Continue file write
mqk¾lrKh ùfï§ continue yuq jQ úg
t;ekska miq Æmfha we;s lsisjla fkdi,ld
python ndysr
B,. jdrfha isg kej; loop l%shd;aul
code [Link]
ù[Link] hhs'
^Æmfha tu mshjr skip lsÍula muKla ±l file read
.; yelsh' iïmQ¾Kfhka wjika fkdfõ'&
The open function - Syntax
Y%s; (Functions)
function call tlla ,nd ÿka úg muKla f = open ("[Link]","mode")
l%shd;aul fõ'
modes
^Y%s; le`oùula&
r - lshùu
Syntax ^ldrl kS;sh& r+ - lshùu" ,sùu
w - ,sùu
def functionname ^mrdñ;sSka& : w+ - ,sùu" lshùu
'''''''''''''''''''''''''''''''''' a - [Link]õ fl<jr ,sùu
'''''''''''''''''''''''''''''''''' a+ - lshùu" fl<jrg tl;= lsÍu
''''''''''''''''''''''''''''''''''
return .......................... [Link] lshùu
f= open ("[Link]","r")
line = [Link] () fma,shla lshùu
return values print (line)
Y%s;hla wjidkfya Y%s; le`oùu l< ia:dkhg [Link]()
hï [Link] ,nd §u fuhska isÿ lrhs'
line=[Link]() iïmQ¾K [Link] lshùu isÿfõ'
mrdñ;Ska (parameters)
def sum(arg1, arg2): [Link] ,Sùu
tot=arg1+arg2 f= open ("[Link]","a")
return tot [Link]("Hello")
[Link]("\t") tab space tlla ;eîu
tot=sum(10,20) [Link]("\n") new line tlla .ekSu
[Link]()
fuys§ arg1=10, arg2=20 f,i mrdñ;Ska wdfoaY
fõ b,lalï [Link] ,sùfï§"
global keyword x = 10
Y%s;hla ;=< global úp,Hla w¾: ±laùug [Link](str(x))
Ndú;d fõ [Link] f,i ,súh hq;=h'

predefined functions ^fmr ieliqï Y%s;&


input() any ()
range () file ()
abs () str ()
all () float ()

[Link] fufyhqï (Basic file operations)


python u`.ska ndysr [Link], l%shdldrlï l,
yelsh'

LASITHA PRASAD
ict
oefkkak
[Link] PAGE 5

You might also like