Real Python
We’re going to start off this series by going through whatever fancies me on Real Python.
Their Introduction to Python seems like a reasonable place to start, so off we go.
Repl.it
We can start sharing and playing with code instantly with repl.it.
IDLE 3
It turns out IDLE is an IDE for Python is perhaps usually installed with most distributions by default, so I figure I’d kick the tires on it. When I went to first open it on the command line it showed me this error:
|
|
Once I installed tk-dev
I was able to open it just fine:
|
|
Then re-install python so that it compiles with the tk
dependency:
|
|
It then opens right up:
|
|
Data Types
Data Types are a great place to start when building up an understanding of what primitive tools you have at your disposal in a language. They also usually come with a few odd traps or gotchas.
Integers
Prefix | Interpretation | Base |
---|---|---|
0b or 0B | Binary | 2 |
0o or 0O | Octal | 8 |
0x or 0X | Hex | 16 |
Floats
Otherwise, they work as expected, just like in most languages, round-off error exists because creating something like “1/10” in binary is nearly impossible without us all agreeing on how to represent it. The IEEE 754 specification is what Python (and most languages) have agreed upon.
Complex Numbers
Seeing as how Python is used by the scientific community, it is of no surprise that it has a way to represent imaginary numbers.
Strings
Work just like you expect, of course with the use of \
allows you to break up strings which is nice, but
also lets you violate the requirements for whitespace in method definitions, so I imagine a more “Python” way might
be to use a String builder pattern, but who knows.
Raw Strings are pretty cool in that it will ignore all the escape characters if you prefix the string with an r
or R
.