Important Notice:

Type Conversion

Type Conversion

2 views 1 min read

Type Conversion (टाइप कन्वर्ज़न) :-

Type Conversion (टाइप कन्वर्ज़न) वह प्रक्रिया (Process) है जिसमें किसी Value (मान) या Variable (चर) के Data Type (डेटा प्रकार) को एक प्रकार से दूसरे प्रकार में बदला जाता है।

उदाहरण के लिए, यदि कोई संख्या Integer (पूर्णांक) के रूप में है और उसे Float (दशमलव संख्या) के रूप में बदलना हो, तो इसे Type Conversion कहते हैं।

English:

Type Conversion is the process of converting the Data Type of a Value or Variable from one type to another.

For example, converting an Integer into a Float or a String into an Integer is called Type Conversion.

Types of Type Conversion (टाइप कन्वर्ज़न के प्रकार)

Python में Type Conversion दो प्रकार की होती है—

  1. Implicit Type Conversion (स्वचालित टाइप कन्वर्ज़न)
  2. Explicit Type Conversion (स्पष्ट/मैनुअल टाइप कन्वर्ज़न)

1. Implicit Type Conversion (स्वचालित टाइप कन्वर्ज़न) :-

जब Python बिना Programmer के निर्देश के स्वयं Data Type बदल देता है, तो उसे Implicit Type Conversion कहते हैं।

English:

When Python automatically converts one data type into another without the programmer's instruction, it is called Implicit Type Conversion.

Example 1-

a = True
b = 5
c=a+b
print(c)
print(type(c))
 
 Output -
15.5
<class 'float'>
 
2. Explicit Type Conversion (स्पष्ट / मैनुअल टाइप कन्वर्ज़न) :-

जब Programmer स्वयं किसी Function का उपयोग करके Data Type बदलता है, तो उसे Explicit Type Conversion कहते हैं।

English:

When the programmer manually converts one data type into another using conversion functions, it is called Explicit Type Conversion.

Example 1:

x = 150

y = str(x)

print(y)
print(type(y))
 
Output-
150
<class 'str'>
 

Example 2:

x = "100"

y = int(x)

print(y)
print(type(y))
 
Output-
100
<class 'int'>
 
 
 

Related Notes