04

Pubblicato il: 03 aprile 2025
sul canale di: MF2Learn
91
6

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, #مشاريع_برمجية, #مهارات_برمجية


In questa pagina del sito puoi guardare il video online 04 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato MF2Learn 03 aprile 2025, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 91 volte e gli è piaciuto 6 spettatori. Buona visione!