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, #مشاريع_برمجية, #مهارات_برمجية
Nesta página do site você pode assistir ao vídeo on-line 04 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário MF2Learn 03 Abril 2025, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 91 vezes e gostou 6 espectadores. Boa visualização!