Data Types Continued
Today we start off by continuing to learn about Data Types!
Most of the rest of this actually isn’t helpful, but I got to play with some built-in functions like
which was kinda fun.
Variables in Python
Python uses the same basic assignment operations that most programming languages.
Types are fluid though, so you can re-assign
n = "hello" and life goes on.
Chained Assignment also works.
The variable reference, e.g.
n, can change based on the object it is referencing.
!! Everything is an Object !!
All of it. Every bit.
A variable points to an object, if nothing points to an object it is considered “orphaned”, and the Garbage Collector will eventually free the memory when it figures it out.
Integer objects have some caching, but seems like there’s even more caching that isn’t documented going on.
The numbers -5 - 256 are cached; however, the Python version on
repl is also caching large integers, as can be witnessed with the
Constants should be uppercase. You can use underscores (snake_case) to
breakup words in a variable name. You cannot star the name of your variable with a digit, you’ll get an “invalid token”
SyntaxError. You can also use unicode characters in names for Python 3.
PEP 8 is the style guide for the language.
These are words you just can’t use:
help lets you look at other stuff too:
Of course, you can programmatically access the keywords list:
Operators and Expressions
In Python, you can multiply a String with an Integer to get it to return the String multiple times.
Python also supports membership (e.g.
contains) with the
Negative indexes of strings are limited by their min-max - i.e. you cannot wrap around a string more than once.