Python में अलग-अलग data types को एक ही data typesमें convert किया जाता है Python में कुछ function ऐसे होते है कि जो data types convert करने में मजबूत करते है |
Types of Converter functions :
- int(a)
- float(a)
- complex(a,b)
1. int() Types Conversion
Syntax :
int(a)
Example :
Float को integer में convert किया गया है string में अगर character होते है तो उसे integer में convert नहीं किया जा सकता है लेकिन string में अगर integer number होते है तो उसे integer में convert किया जा सकता है |
Source Code :
a = "123"
print(int(a))
b = 2.658
print(int(b))
2. float() type Conversion
Syntax :
float(a)
Example :
Integer को float में convert किया गया है string में अगर character होते है तो उसे floating-point number में convert नहीं किया जा सकता है लेकिन string में अगर integer number या floating-point number होते है तो उसे floating-point में convert किया जा सकता है |
Source Code :
a = "123"
print(float(a))
b = "123.564"
print(float(b))
c = 2
print(float(c))
3. Complex() Type Conversion
Syntax :
complex(a,b)
Parameters :
- a : यहाँ पर ‘a’ ये real Number होता है |
- b : Optional. यहाँ पर ‘b’ ये imaginary हिस्सा होता है अगर दिया नहीं जाता तो डिफ़ॉल्ट वैल्यू ‘0’ होती है
Source Code :
a = "123"
print(complex(a))
b = "123.564"
print(complex(b))
c = 2
print(complex(c), end="\n\n")
d = 123
e = 58
print(complex(d, e))
f = "123"
g = 58
print(complex(f, g))
String
String ये characters का set होता है | characters; letters, numbers या special symbols हो सकते है |
Python में single (‘ ‘) या double (” “) quotes के अंदर लिखे जाते है string ये immutable data type है |
Source Code :
str1 = "Hello World"
str2 = "Hello Friends"
print(str1)
print(str2)
ज्यादातर programming language में string को index में print किया जाता है उसी प्रकार से python में भी string को indexes से print किया जाता है | string के सबसे पहले character को index ‘0’ से शुरू होती है और string के सबसे आखरी index ‘-1’ होती है |

Source Code :
str = "Hello World"
print("First letter in string :", str[0])
print("Last letter in string :", str[-1])
print("Second last letter in string :", str[-2])
