Objects and Data Structure Assessment Test Flashcards
Numbers
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
Strings
Strings are a record of text information and are constructed using double or single quotes
Lists
lists are a collection of items constructed using brackets [] and commas that seperate every element.
Tuples
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
Write an equation that uses multiplication, division, an exponent, addition, and subtraction that is equal to 100.25
100.25 = 1.25 + (5**2*8/2) - 1
What is the value of the expression 4 * (6 + 5)
44
What is the value of the expression 4 * 6 + 5
29
What is the value of the expression 4 + 6 * 5
34
What is the type of the result of an expression 3 + 1.5 + 4?
Floating point number
What would you use to find a number’s square root, as well as it’s square?
Square root: 100 ** 0.5 = 10.0
Square: 10 ** 2 = 100
s = ‘hello’
# Print out the e string using indexing
s[1]
‘e’
s = ‘hello’
# Reverse the string using slicing
s[::-1]
s = ‘hello’
# Print out the ‘o’
Method 1:
Method 2:
Method 1: s[4]
Method 2: s[-1]
Build this list [0,0,0] two seperate ways.
Method 1:
Method 2:
Method 1: [0]*3
Method 2:
list1 = [0,0,0]
list1
Reassign ‘hello’ in this nested list to say ‘goodbye’ instead.
list3 = [1,2,[3,4,’hello’]]
list3[2][2] = ‘goodbye’
list3 = [1,2,[3,4,’hello’]]