FIT1008 Lecture Notes - Lecture 5: Class Variable

73 views2 pages
Data$structures
="provide"a"particular"way"in"which"data"is"physically"organised"(so"that"certain"ops"
can"be"efficiently"performed)
="implementation"so"data"can"be"accessed"an"organised
Organise"info,"eg"using"graphs,"tables,"lists"etc
Types:
Array
Fixed"size
Data"items"stored"sequentially
Each"item"occupies"same"amount"of"space
List
="arrays"of"references
Mutable"="can"be"changed"without"creating"a"new"object
Eg."x"="[4,"0.5,"'hi']
X"has"a"box"for"itself"which"points"to…
A"larger"box"containing:
Length"of"list"within"one"box
§
Each"list"item"within"2"boxes
§
Names
="all"identifiers"such"as"variables,"functions,"methods,"modules,"types"etc.
Can"only"refer"to"one"thing"at"a"time
Namespace
="a"mapping"of"names"to"objs,"like"a"dictionary
Alrdy"created"when"interpreter"starts,"with"the"names"of"the"built-in"
functions
Each"file/module"has"its"own"namespace
Don't"put"2"classes/functions"with"same"name"in"one"file,"the"2nd"
definition"will"override"the"1st
Functions"also"have"local"namespaces"created"when"called,"and"forgotten"
when"finished
Scope
="block"of"text"where"a"namespace"is"directly"accessible
Eg."from point import Point
-brings"Point"to"current"namespace,"so"no"need"for"point.Point
Often"there"are"several"scopes"in"operation:
The"method"executing
The"class"where"the"method"is"defined
The"module"where"the"class"is"defined
The"interpreter" executing"code
Determined"statically"-by"looking"at"program
Used"dynamically"-Python"searches"for"names"during"runtime:
Innermost"scope"--- contains"all"local"names"in"method's"namespace1)
Scope"of"enclosing"functions"--- nearest-to-outer,"contains"nonlocal"and"
nonglobal"names
2)
Module's"global"names"--- i.e."namespace"of"module3)
Namespace"containing"built-in"names4)
Class"variables
="variables"whose"values"are"shared"by"all"class"instances
[example]
class Silly:
i = 8
silly.i --> 8 **"exists"without"object."Value"accessed"through"class.
s1 = Silly()
s1.i --> 8 **"all"instances"share"same"class"variable"value
Week$5:$abstraction$-data$structures
Thursday,"14"June"2018
21:29
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Document Summary

= provide a particular way in which data is physically organised (so that certain ops can be efficiently performed) = implementation so data can be accessed an organised. Organise info, eg using graphs, tables, lists etc. Mutable = can be changed without creating a new object. X has a box for itself which points to . = all identifiers such as variables, functions, methods, modules, types etc. Can only refer to one thing at a time. = a mapping of names to objs, like a dictionary. Alrdy created when interpreter starts, with the names of the built-in functions. Don"t put 2 classes/functions with same name in one file, the 2nd definition will override the 1st. Functions also have local namespaces created when called, and forgotten when finished. = block of text where a namespace is directly accessible. Brings point to current namespace, so no need for point. point. Used dynamically - python searches for names during runtime:

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents