Get Data Type & Data Type Conversion In Python | දත්ත වර්ගය ලබාගැනීම සහ පරිවර්තනය | SL Android

Channel:
Subscribers:
18,100
Published on ● Video Link: https://www.youtube.com/watch?v=DSSiR1m3fBQ



Duration: 12:26
328 views
0


Python programming Sinhala Full course

Get Data Type & Data Type Conversion In Python | දත්ත වර්ගය ලබාගැනීම සහ පරිවර්තනය | SL Android

Python full course sinhala
සිංහල පයිතන් ක්‍රමලේඛණය කිරීම.

Type Conversion in Python

Python defines type conversion functions to directly convert one data type to another which is useful in day to day and competitive programming. This article is aimed at providing the information about certain conversion functions.

1. int(a,base) : This function converts any data type to integer. ‘Base’ specifies the base in which string is if data type is string.

2. float() : This function is used to convert any data type to a floating point number
.


 

# Python code to demonstrate Type conversion

# using int(), float()

  

# initializing string

s = "10010"

  

# printing string converting to int base 2

c = int(s,2)

print ("After converting to integer base 2 : ", end="")

print (c)

  

# printing string converting to float

e = float(s)

print ("After converting to float : ", end="")

print (e)

Output:

After converting to integer base 2 : 18 After converting to float : 10010.0

3. ord() : This function is used to convert a character to integer.

4. hex() : This function is to convert integer to hexadecimal string.

5. oct() : This function is to convert integer to octal string.

# Python code to demonstrate Type conversion

# using  ord(), hex(), oct()

  

# initializing integer

s = '4'

  

# printing character converting to integer

c = ord(s)

print ("After converting character to integer : ",end="")

print (c)

  

# printing integer converting to hexadecimal string

c = hex(56)

print ("After converting 56 to hexadecimal string : ",end="")

print (c)

  

# printing integer converting to octal string

c = oct(56)

print ("After converting 56 to octal string : ",end="")

print (c)

Output:

After converting character to integer : 52 After converting 56 to hexadecimal string : 0x38 After converting 56 to octal string : 0o70

6. tuple() : This function is used to convert to a tuple.

7. set() : This function returns the type after converting to set.

8. list() : This function is used to convert any data type to a list type.

# Python code to demonstrate Type conversion

# using  tuple(), set(), list()

  

# initializing string

s = 'geeks'

  

# printing string converting to tuple

c = tuple(s)

print ("After converting string to tuple : ",end="")

print (c)

  

# printing string converting to set

c = set(s)

print ("After converting string to set : ",end="")

print (c)

  

# printing string converting to list

c = list(s)

print ("After converting string to list : ",end="")

print (c)

Output:

After converting string to tuple : ('g', 'e', 'e', 'k', 's') After converting string to set : {'k', 'e', 's', 'g'} After converting string to list : ['g', 'e', 'e', 'k', 's']

9. dict() : This function is used to convert a tuple of order (key,value) into a dictionary.



10. str() : Used to convert integer into a string.

11. complex(real,imag) : : This function converts real numbers to complex(real,imag) number.

# Python code to demonstrate Type conversion

# using  dict(), complex(), str()

  

# initializing integers

a = 1

b = 2

  

# initializing tuple

tup = (('a', 1) ,('f', 2), ('g', 3))

  

# printing integer converting to complex number

c = complex(1,2)

print ("After converting integer to complex number : ",end="")

print (c)

  

# printing integer converting to string

c = str(a)

print ("After converting integer to string : ",end="")

print (c)

  

# printing tuple converting to expression dictionary

c = dict(tup)

print ("After converting tuple to dictionary : ",end="")

print (c)

Output:

After converting integer to complex number : (1+2j) After converting integer to string : 1 After converting tuple to dictionary : {'a': 1, 'f': 2, 'g': 3}

-~-~~-~~~-~~-~-
Please watch: "How to code a simple calculator ( Project 01) |C Programming සිංහල Tutorial Episode 25 |SL Android"
https://www.youtube.com/watch?v=A6nvSvDcsUA
-~-~~-~~~-~~-~-




Other Videos By SL Android


2020-04-25Termux Tools Part 2 Vulnerable Scanning| Termux Sinhala Tutorials Episode 06 | SL Android |SL Coders
2020-04-25Exploring Termux Tools: Unveiling the Power of Termux Hacking😍 |Termux Sinhala Tutorials Episode 05
2020-04-23Exploring Termux Programming Languages:Tools, and More! (Sinhala) 🔐📱 Termux tutorials Episode 04
2020-04-23Termux තුල භාවිතාවන පැකේජ | Termux Packages | Termux Sinhala Tutorials Episode 03 | SL Android
2020-04-22How Create A Youtube Channel Like A Professional | SL Android
2020-04-22Termux මූලික විධාන ගැන දැනගමු | Basic Commands | Termux Sinhala Tutorials Episode 02 |SL Android
2020-04-22Termux මූලික හැදින්වීම |Termux Sinhala Tutorials | introduction Episodes 01 | SL Android |SL Coders
2020-04-21Top Whatsapp Tricks 2020 | Whatsapp වලින් වෙනස්ම විදියකට Massage කරමු | SL Android
2020-04-20Amazing Flash Drive |You can put them all over the place Flash Drive |SL Android
2020-04-18Ip Address Checker For Python |Sinhala python|SL Android
2020-04-17Get Data Type & Data Type Conversion In Python | දත්ත වර්ගය ලබාගැනීම සහ පරිවර්තනය | SL Android
2020-04-16How to Create An Animation Spider web on Python |SL Android
2020-04-14Get Mobitel Rs 49 Data Card Totaly Free of charge | 49 Data Card එකක් නොමිලේ ගමු |SL Android
2020-04-04Dialog New OFFER | Get Free data , D2D SMS 250 & D2D min 250 | SL Android
2020-04-02How To Get Mobie Reload With 10% Discount ..Any Network Sinhala.| Using Pay master | SL Android
2020-04-01Get free Data | Get 1 GB Data For Free Using Mobitel Data mart App.
2020-03-19Slicing Operator in python programming | සිංහල පයිතන් Episode 12 | SL Android
2020-03-16Index operator In Python programming | සිංහල පයිතන් Episode 11 | SL Android
2020-03-14Separator & End in python(පයිතන් වල භාවිතාවන end සහ sep)| සිංහල පයිතන් Episode 10 | SL Android
2020-03-14Len Function in Python | Sinhala Python Episode 09 | SL Android
2020-03-12Python Comments |Sinhala python Episode 08 | SL Android



Tags:
sinhala python programming caurse
sinhala python
index operator
slicing operator
SL Android
Android application
python introduction
python introduction for beginners
python introduction tutorial
python introduction course
python sinhala
python projects
python
python programming sinhala