Monday, April 6, 2020

PYTHON -3 (DATA TYPES)

python -3 කොටස
Data types in python /දත්ත වර්ග

Python හි යෙදෙන දත්ත වර්ග 9 ක් ඇත: ඒවා 
 string,integer, float, complex, bool,  list, tuple, set and dictionary. 
ලෙස හඳුන්වයි

·         strings- string
·         numbers 
o   integer numbers - integer
o   floating-point numbers - float
o   complex numbers  -complex
·         tuples - tuple
·         lists -list

·         sets -set
dictionaries - dictionary

යම් දත්තයක දත්ත වර්ගය පරීක්ෂා කිරීම සඳහා type()  නැමැති function එක භාවිතා කරන්න.
උදා
>>> type( 'Hello, World! ' )
<class 'str'>

>>> type(17)
<class'int'>
Python පරිගණක භාෂාවේ එන දත්ත වර්ග මොනවාද යන්න අවබෝධ කර ගැනීම සඳහා type ( ) නැමැති function එක භාවිතා කරන්න

type(“hello”)

type(“4.5”)

type(4.5)

type(45)

type([])

x=”hello”
type(x)

x=45
type(x)

x=45.5
type(x)



string වර්ගය

>>> 3+'3'  හි පිළිතුර කුමක් වේද ?

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    3+'3'
TypeError: unsupported operand type(s) for +: 'int' and 'str'
දත්ත වර්ග 2 ක් නිසා මෙම දෝෂය ලැබේ.
------------------------------------------------------------------
>>> '=' + 10   හි පිළිතුර කුමක් වේද ?
දත්ත වර්ග 2 ක් නිසා පෙර සඳහන්දෝෂයම ලැබේ.
------------------------------------------------------------------
එහෙත් >>> '= ' * 10 හි පිළිතුර ලෙස  '==========' ලැබේ.

------------------------------------------------------------------
 >>> "2020 " + 'is good for you'  හි පිළිතුර කුමක් වේද ?
අක්ෂර සමග අක්ෂර එකතු කිරීමේ දී ඒවා එකට ලියා දක්වයි.
එනම් '2020 is good for you' ලෙස පිළිතුර ලැබේ. 
------------------------------------------------------------------

“hello how are you” යනු string වර්ගයේ දත්තයකට උදාහරණයකි. 
       String එකක අඩංගු සෑම සං‍කේතයක්ම අංකයකින් හැදින්විය හැකිය:
      උදාහරණය        name = “sara.crc"      නම්

     
index
0
1
2
3
4
5
6
7
character
s
a
r
a
.
c
r
c

String එකක තනි සංකේතයක් වෙනම ලබා ගැනීම

>>>name[0] මගින් "s" යන අගය ලැබේ.
       
         variableName [ index ]


String properties
name = "sarath Bogahapitiya"      නම්
length = len(name)         
big_name = str.upper(name)

print (big_name, "has", length, "characters")

Output:                SARATH BOGAHAPITIYA  has 18 characters


Integer දත්ත වර්ගය

සකසමින් පවතී.....

No comments:

Post a Comment

Blog Archive

Memory Locatıons and Addresses (Week 3) - ppt download

Memory Locatıons and Addresses (Week 3) - ppt download : Memory Locations and addresses We will first consider how the memory of a computer...

Total Pageviews

Followers