04 #Python - Type Casting
CODE :
Type casting, also known as type conversion,
is the process of converting a value from one data type to another.
In Python, this is often done using built-in functions.
Why is Type Casting Important?
1. To perform operations between different data types
2. To meet specific requirements of functions or methods
3. To change how data is represented or stored
int(), float(), str(), bool()
-----------------------------------------------
Float to int
print(int(4.7)) # Output: 4
print(int(-3.9)) # Output: -3
String to int
print(int("10")) # Output: 10
Boolean to int
print(int(True)) # Output: 1
print(int(False)) # Output: 0
-----------------------------------------------
2. float()
Integer to float
print(float(5)) # Output: 5.0
String to float
print(float("3.14")) # Output: 3.14
Boolean to float
print(float(True)) # Output: 1.0
-----------------------------------------------
3. str()
Integer to string
print(str(42)) # Output: "42"
Float to string
print(str(3.14)) # Output: "3.14"
Boolean to string
print(str(True)) # Output: "True"
-----------------------------------------------
4. bool()
Integer to boolean
print(bool(1)) # Output: True
print(bool(0)) # Output: False
Float to boolean
print(bool(0.0)) # Output: False
print(bool(0.1)) # Output: True
String to boolean
print(bool("")) # Output: False
print(bool("Hello")) # Output: True
WhatsApp : 009647812081244
#Python, #بايثون, #LearnPython, #تعلم_بايثون, #PythonForBeginners, #PythonProgramming, #برمجة, #Coding, #كود, #Programming, #برمجة_بايثون, #PythonTutorial, #تعلم_البرمجة, #PythonCourse, #كورس_بايثون, #CodingForBeginners, #برمجة_للمبتدئين, #DataScience, #تحليل_البيانات, #MachineLearning, #تعلم_الآلة, #AI, #ذكاء_اصطناعي, #Tech, #CodingLife, #كود_بايثون, #CodeNewbie, #مشاريع_برمجية, #مهارات_برمجية
En esta página del sitio puede ver el video en línea 04 de Duración hora minuto segunda en buena calidad , que subió el usuario MF2Learn 03 abril 2025, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 91 veces y le gustó 6 a los espectadores. Disfruta viendo!