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
Q

Attributes definition

A

represent various pieces of code and data which make up the object

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

How to access attribute

A

object.attribute

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

Example of upper attribute

A

‘bob’.upper

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

Program to make ‘bob’ into ‘BOB’

A

‘bob’.upper()

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

Scope definition

A

a region of code in which a name can be used and outside of which the name cannot be easily accessed

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

2 ways of delimiting scope

A

Functions

Modules

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

Namespace definition

A

A particular place in which names specific to a module reside

32
Q

Seven Common Sequence Types

A

strings, Unicode strings, lists, tuples, bytearrays, buffers, xrange objects

33
Q

2 Containers for sequential data

A

Dictionaries

Sets

34
Q

Accessing characters in strings and elements in arrays

A

[ ]

35
Q

Accessing characters in strings example

A

> > > “Hello, world!” [0]
‘H’
“Hello, world!” [4]
‘o’

36
Q

Accessing characters in strings negative example

A

> > > “Hello, world!”[-2]
‘d’
“Hello, world!”[-13]
‘H’

37
Q

Slicing definition

A

Using indexes to divide a string into a smaller substring

38
Q

Slicing Operator

A

[ : ]

39
Q

Slicing example

A

> > > “Hello, world!” [3:9]

‘lo, wo’

40
Q

List definition

A

a list of values, organized in order

41
Q

List operator

A

[ ]

42
Q

Values in list separated by

A

,

43
Q

List example

A

spam = [“bacon”, “eggs”, 42]

44
Q

How to access bacon from the list: spam = [“bacon”, “eggs”, 42]

A

> > > spam[0]

45
Q

The length of spam. spam = [“bacon”, “eggs”, 42]

A

> > > len(spam)

3

46
Q

Can lists be sliced?

A

yes

47
Q

Add items to a list function

A

append()

48
Q

Appending items to a list example

A

> > > spam.append(10)
spam
[‘bacon’, ‘eggs’, 42, 10]

49
Q

Inserting an item into a list function

A

insert()

50
Q

Inserting item into list example

A

> > > spam.insert(1, ‘and’)
spam
[‘bacon’, ‘and’, ‘eggs’, 42, 10]

51
Q

Deleting items from a list function

A

del

52
Q

Delete item from list example

A

> > > del spam[1]
spam
[‘bacon’, eggs’, 42, 10]

53
Q

Tuple definition

A

list that can’t be changed

54
Q

Tuple function

A

,

55
Q

Tuple example

A

unchanging = “rocks”, 0, “the universe”

56
Q

Dictionary definition

A

Like a list but not bound to numbers

57
Q

2 parts of a dictionary element

A

Key

Value

58
Q

Dictionary operator

A

{ }

59
Q

Separator between key and value

A

:

60
Q

Dictionary example

A

> > > definitions = {“guava”: “a tropical fruit”, “python”: “a programming language”}

61
Q

Pulling up a definition example

A

> > > definitions[“guava”]

‘a tropical fruit’

62
Q

Set definition

A

Like a list but unordered and do not allow duplicate values

63
Q

Set operator

A

set([ ])

64
Q

Set example

A

> > > mind = set([42, ‘a string’, (23, 4)])

65
Q

Frozenset definition

A

an immutable version of a set

66
Q

Frozenset operator

A

frozenset([ ])

67
Q

Frozenset example

A

> > > frozen=frozenset([‘life’, ‘universe’, ‘everything’])

68
Q

4 types of data

A

Numeric
Sequences
Sets
Mappings

69
Q

4 numeric types

A
int
long (only python 2)
float
complex
70
Q

5 sequence types

A
str
bytes (only python 3)
byte array (only python 3)
list
tuple
71
Q

2 set types

A

set

frozenset

72
Q

1 mapping type

A

dict

73
Q

Mutable objects definition

A

objects that can be changed after they’re created

74
Q

Immutable object definition

A

objects that can’t be changed after they’re made

75
Q

8 immutable types

A

int, float, complex, str, bytes, tuple, frozenset, bool

76
Q

5 mutable types

A
array
byte array
list
set
dict