Understanding the syntax Flashcards

1
Q

CALLING A FUNCTION

pop function

.pop( )

var1.pop(var2)

.pop(var1)

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

CALLING A DICT

mystuff[‘apples’]

why [ ]? not { } or ( )

what does ‘ ‘ mean to apples

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

CALLING A MODULE

mystuff.apples( )

Why is import my stuff important to do before this?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

IMPOTING FROM A MODULE

import mystuff

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

CALLING A CLASS

class class_name(object):

instance_name = class_name(object )

instance_name.function_name

A
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly