reading-notes

reading notes for code fellows


Project maintained by dLeigh01 Hosted on GitHub Pages — Theme by mattgraham

Starting Python

These are some simple concepts for starting out in Python, and as such it is good to get a handle on them before we get into the language and start work on anything that will build off of these concepts.

Big O Notation

Big O Notation is used to describe the complexity or performance of an algorithm (as in the execution time or space used) in the worst case scenario.

Python Names and Values

Python works a lot like other languages, in that underlying mechanisms are simple, but can have surprising effects.

Names refer to values, and assignment makes a specific name refer to a specific value such as x = 23. Multiple names can refer to a single value, and names are reassigned independantly. Values will continue to exist until their reference value becomes 0.

In Python, assignment never copies data, which means that if two names are assigned to the same data set any changes will appear under either name. (This is otherwise known as mutable aliasing)

Immutable values cannot be changed in place or alias (ints, floats, strings, tuples) When “changes” are referenced in these types, it is more accurately defined as ‘rebinding’.

Names are not the only references, for instance, list elements are each references, and so are object attributes and anything that can appear on the left side of an assignment.

The best way to avoid surprises with values in functions is to create new things rather than mutating values.

In Python, names have no type and values have no scope.

Things I Want to Know More About

I understand a bit more now about mutable vs immutable values and why some change and others don’t between names, but I still think I need to go a bit more in depth with it to get the concept fully cemented in my head.

Discussion

The different notations of O are like a lot of different math problems, and they work like a pessimist trying to prepare you for the worst case scenario, while the referential nature of Python as a language is similar to, but slightly different from other languages I have worked with in that, yes, it is not strictly typed, but you need to be strict about the way you are assigning things or else it will all get out of hand.

[< table of contents]

[< home]