Understanding the syntax Flashcards
CALLING A FUNCTION
pop function
.pop( )
var1.pop(var2)
.pop(var1)
Removes and returns an object from a list.
Calls the pop function.
from container var1, run pop function on var2
OR
Call pop function on parameter var2 which is in container var1
Call pop function on var1
CALLING A DICT
mystuff[‘apples’]
why [ ]? not { } or ( )
what does ‘ ‘ mean to apples
From dict mystuff retrieve object (string) apples
Because the objects in a dict are formatted in a list style linear sequence i.e.
‘apples’ : ‘green fruit’
‘peaches’ : ‘orange fruit’
Signifies that the word apple is a string. Otherwise it would be a variable [apple] the program would try to retrieve.
CALLING A MODULE
mystuff.apples( )
Why is import my stuff important to do before this?
From module mystuff, run function apples
The code from module/file (in this case mystuff.py) must be imported to your program before it can be run.
You cannot run code direct from its module/file it must be imported to your program then run.
IMPOTING FROM A MODULE
import mystuff
The code from module/file (in this case mystuff.py) must be imported to your program before it can be run.
You cannot run code direct from its module/file it must be imported to your program then run.
CALLING A CLASS
class class_name(object):
instance_name = class_name(object )
instance_name.function_name
Class has the name class_name with the parameter of object contents From class retrieve object and its contents.
Instance
Call a function on an instance