wikibooks Python 1 Flashcards

1
Q

print “hello world”

A

print (‘hello world’)

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

Variable definition

A

something that holds a value that can change

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

Variable in which red is equal to 5

A

red = 5

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

Variable in which blue equals 10

A

blue = 10

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

Program which runs with the variables red and blue based on previous variable assignment placing red and then blue

A

print (red, blue)

5 10

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

Name of Variable location

A

left of equals sign

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

Value of Variable location

A

right of equals sign

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

String definition

A

a list of characters in order

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

Three ways to declare a string

A
Single quotes (‘)
Double quotes (“)
Triple quotes (“””)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Escaping the symbol definition

A

Placing a backslash before a symbol to show that the symbol should be included in the string

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

Escaping a quotation mark example

A

print&raquo_space;> (“So I said, \”You don’t know me! You’ll never understand me!\””)

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

Concatenation operator

A

+

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

Concatenation example

A

> > > print (“Hello, “ + “world!”)

Hello, world!

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

Repeat strings operator

A

*

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

Repeat strings example

A

> > > print (“bouncy, “ * 3)

bouncy, bouncy, bouncy,

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

Function which finds the length of a string

A

len()

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

Finding string length example

A

> > > print (len(“Hello, world!”))

13

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

Function that turns a string into an integer

A

int()

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

Function that turns an integer into a string

A

str()

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

Function which outputs the information to the user

A

print()

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

Function which asks the user for a response and returns that response

A

input()

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

Are variables case-sensitive?

A

yes

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

Can spaces be substituted for tabs?

A

no

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

Object definition

A

aggregations of code and data which typically represent the pieces in a conceptual model of a system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Attributes definition
represent various pieces of code and data which make up the object
26
How to access attribute
object.attribute
27
Example of upper attribute
‘bob’.upper
28
Program to make ‘bob’ into ‘BOB’
‘bob’.upper()
29
Scope definition
a region of code in which a name can be used and outside of which the name cannot be easily accessed
30
2 ways of delimiting scope
Functions | Modules
31
Namespace definition
A particular place in which names specific to a module reside
32
Seven Common Sequence Types
strings, Unicode strings, lists, tuples, bytearrays, buffers, xrange objects
33
2 Containers for sequential data
Dictionaries | Sets
34
Accessing characters in strings and elements in arrays
[ ]
35
Accessing characters in strings example
>>> “Hello, world!” [0] ‘H’ >>> “Hello, world!” [4] ‘o’
36
Accessing characters in strings negative example
>>> “Hello, world!”[-2] ‘d’ >>> “Hello, world!”[-13] ‘H’
37
Slicing definition
Using indexes to divide a string into a smaller substring
38
Slicing Operator
[ : ]
39
Slicing example
>>> “Hello, world!” [3:9] | ‘lo, wo’
40
List definition
a list of values, organized in order
41
List operator
[ ]
42
Values in list separated by
,
43
List example
spam = [“bacon”, “eggs”, 42]
44
How to access bacon from the list: spam = [“bacon”, “eggs”, 42]
>>> spam[0]
45
The length of spam. spam = [“bacon”, “eggs”, 42]
>>> len(spam) | 3
46
Can lists be sliced?
yes
47
Add items to a list function
append()
48
Appending items to a list example
>>> spam.append(10) >>>spam [‘bacon’, ‘eggs’, 42, 10]
49
Inserting an item into a list function
insert()
50
Inserting item into list example
>>> spam.insert(1, ‘and’) >>> spam [‘bacon’, ‘and’, ‘eggs’, 42, 10]
51
Deleting items from a list function
del
52
Delete item from list example
>>> del spam[1] >>> spam [‘bacon’, eggs’, 42, 10]
53
Tuple definition
list that can’t be changed
54
Tuple function
,
55
Tuple example
unchanging = “rocks”, 0, “the universe”
56
Dictionary definition
Like a list but not bound to numbers
57
2 parts of a dictionary element
Key | Value
58
Dictionary operator
{ }
59
Separator between key and value
:
60
Dictionary example
>>> definitions = {“guava”: “a tropical fruit”, “python”: “a programming language”}
61
Pulling up a definition example
>>> definitions[“guava”] | ‘a tropical fruit’
62
Set definition
Like a list but unordered and do not allow duplicate values
63
Set operator
set([ ])
64
Set example
>>> mind = set([42, ‘a string’, (23, 4)])
65
Frozenset definition
an immutable version of a set
66
Frozenset operator
frozenset([ ])
67
Frozenset example
>>> frozen=frozenset([‘life’, ‘universe’, ‘everything’])
68
4 types of data
Numeric Sequences Sets Mappings
69
4 numeric types
``` int long (only python 2) float complex ```
70
5 sequence types
``` str bytes (only python 3) byte array (only python 3) list tuple ```
71
2 set types
set | frozenset
72
1 mapping type
dict
73
Mutable objects definition
objects that can be changed after they’re created
74
Immutable object definition
objects that can’t be changed after they’re made
75
8 immutable types
int, float, complex, str, bytes, tuple, frozenset, bool
76
5 mutable types
``` array byte array list set dict ```