Objects and Data Structure Assessment Test Flashcards

1
Q

Numbers

A

There are various number type in Python e.g integers which are just whole numbers like 1 or 2, and floating point numbers which have a decimal point 2.4 or 1.0. Exponentials like squares and square roots come under floating point numbers

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

Strings

A

Strings are a record of text information and are constructed using double or single quotes

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

Lists

A

lists are a collection of items constructed using brackets [] and commas that seperate every element.

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

Tuples

A

Tuples are like lists however, unlike lists tuples are immutable meaning they cannot be added to or changed. Tuples can be used for day or months on a calendar

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

Write an equation that uses multiplication, division, an exponent, addition, and subtraction that is equal to 100.25

A

100.25 = 1.25 + (5**2*8/2) - 1

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

What is the value of the expression 4 * (6 + 5)

A

44

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

What is the value of the expression 4 * 6 + 5

A

29

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

What is the value of the expression 4 + 6 * 5

A

34

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

What is the type of the result of an expression 3 + 1.5 + 4?

A

Floating point number

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

What would you use to find a number’s square root, as well as it’s square?

A

Square root: 100 ** 0.5 = 10.0
Square: 10 ** 2 = 100

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

s = ‘hello’
# Print out the e string using indexing

A

s[1]
‘e’

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

s = ‘hello’
# Reverse the string using slicing

A

s[::-1]

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

s = ‘hello’
# Print out the ‘o’
Method 1:
Method 2:

A

Method 1: s[4]
Method 2: s[-1]

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

Build this list [0,0,0] two seperate ways.
Method 1:
Method 2:

A

Method 1: [0]*3
Method 2:
list1 = [0,0,0]
list1

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

Reassign ‘hello’ in this nested list to say ‘goodbye’ instead.
list3 = [1,2,[3,4,’hello’]]

A

list3[2][2] = ‘goodbye’
list3 = [1,2,[3,4,’hello’]]

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

Sort the list in two methods:
list4 = [5,3,4,6,1]

A

Method 1: .sorted(list4)
Method 2:
list4.sort()
list4

17
Q
  1. Grab ‘hello’ using indexing and slicing.
    d = {‘simple_key’ : ‘hello’}
A

d[‘simple_key]

18
Q
  1. Grab ‘hello’ using indexing and slicing.
    d = {‘k1: [1,2,{‘k2’ :[‘this is tricky’,{‘tough’ :[1,2,[‘hello’]]}]}]}
A

d’[k1’][2][‘k2’][-1][‘tough’][2]

19
Q
  1. Grab ‘hello’ using indexing and slicing.
    d = {‘k1’: {‘k2’ : ‘hello’}}
A

d[‘k1’][‘k2’]

20
Q
  1. d = {‘k1’ :[{‘nest_key’ :[‘this is deep’, [‘hello’]]}]}
A

d[‘k1’][0][‘nest_key’][-1]

21
Q

Can you sort a dictionary? Why or why not?

A

No, because normal dictionaries are mappings not a sequence

22
Q

How do you create a tuple?

A

t = (1,2,3)

23
Q

What is the major difference between tuples and lists

A

Tuples, unlike lists are immutable which means they cannot be added to or changed

24
Q

What’s unique about a set?

A

Sets are unique because they don’t allow for duplicate items

25
Q

Use a set to find the unique values of the list below:
list5 = [1,2,2,33,4,4,11,22,3,3,2]

A

set(list5)

26
Q

2 > 3

A

False

27
Q

3 <= 2

A

False

28
Q

3 == 2.0

A

False

29
Q

3.0 == 3

A

True

30
Q

4**0.5 !=2

A

False

31
Q

l_one = [1,2,[3,4]]
l_two = [1,2,{‘k1’ :4}]
-
True or False?
l_one[2][0] >= l_two[2][‘k1’]

A

False