It’s time to dig deeper into our work with numbers (including math) and strings.
What is Your Type?
First of all, it might be handy (especially as you are learning) having Python report the type of a variable or a literal value. For example:
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = "This is cool!"
More on Division
Division in Python comes in two variations:
/ carries out floating point division
// caries out integer (truncating) division
>>> 15 / 4
>>> 15 // 4
Many of the math precedence rules would make sense to us (those that took some math in school!) For example, multiplication wins over addition. But fortunately, Python supports the use of ( ) to indicate precedence. Thanks to the use of parenthesis, we do not have to worry about default behaviors. Here is an example:
>>> 10 + 20 + (10 * 7)
What Base Are You On?
Of course, Python permits you to speak to it in more than Base 10. Use the following:
0b for binary
0o for octal
0x for hex
Change Your Type!
Use the int() function to change other data types to an integer:
I hope you had fun in this lesson! More soon!