Day 9 – Type Casting in Python: Explicit & Implicit Type Conversion

🚀 Passionate DevOps Engineer with expertise in cloud computing, CI/CD, and automation. Skilled in Linux, Docker, Kubernetes, Terraform, Ansible, and Jenkins. I specialize in building scalable, secure, and automated infrastructures, optimizing software delivery pipelines, and integrating DevSecOps practices. Always exploring new ways to enhance deployment workflows and bridge the gap between development and operations.
What is Type Casting?
Type casting, also called type conversion, is the process of converting a value from one data type to another.
For example, a value stored as a string can be converted into an integer:
a = "10"
b = int(a)
print(b)
print(type(b))
Output:
10
<class 'int'>
Python provides several built-in functions that can be used for type conversion, including:
| Function | Converts a value to |
|---|---|
int() |
Integer |
float() |
Floating-point number |
str() |
String |
bool() |
Boolean |
list() |
List |
tuple() |
Tuple |
set() |
Set |
dict() |
Dictionary, when the input has a valid dictionary-compatible structure |
ord() |
Unicode code point of a single character |
hex() |
Hexadecimal string representation of an integer |
oct() |
Octal string representation of an integer |
Types of Type Conversion
Python type conversion can generally be understood in two ways:
Explicit Type Conversion
Implicit Type Conversion
1. Explicit Type Conversion
Explicit type conversion happens when the programmer manually converts a value from one data type to another.
