python logo

Type Casting

Type casting is the process of converting one data type to another data type, like a string to an integer or float and vice versa. Example: num_string1 = "30" num_string2 = "20" num_strings = num_string1 + num_string2 print(num_strings) print(type(num_strings)) nums_typecast = int(num_string1) + int(num_string2) print(nums_typecast) print(type(nums_typecast)) try_typecast = int(num_string1 + num_string2) print(try_typecast) print(type(try_typecast)) In the code above, the data type of num_string1 and num_string2 are strings so when they are added using + operator, the result will just be a string concatenation and the data type is still a string....

February 12, 2022 · 1 min · Kei
python logo

Numbers

Type of Numbers : Integers : Whole numbers Floats (Floating Point numbers) : Decimal numbers Complex numbers : Numbers that have real and imaginary parts Some maths operations that can be done using Python are: Addition + : Adding numbers Subtraction - : Subtracting numbers Division / : Dividing numbers Multiplication * : Multiply numbers Exponential ** : x to the power of y Modulo % : Leftover number from division Floor division // : Returns the value of division without decimal points Example of Floor Division // There’s a math module that can be imported to perform mathematical operations on numbers...

February 12, 2022 · 1 min · Kei