Python Numbers
Order of Operations
• PEMDAS applies
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Number Strangeness
• because of how binary computer works
>>>
0.1
+
0.2
0.30000000000000004
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Casting Numbers to Strings
>>>
print
(
'the answer is '
+
8
)
# error
>>>
print
(
'the answer is '
+
str
(
8
))
# type casting
# int() str()
# Numbers
years =
8
# Cast
print
(
"UNATCO has existed for "
+
str
(years) +
"years"
)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Silent Type Bugs
# Fails silently
how_many =
"8"
# Cast
6
* how_many
# 888888
6
*
int
(how_many)
# 48
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
print() is Flexible
• String concatenation is not
Index