Topic 1 Flashcards

(41 cards)

1
Q

Python counts from

A

0

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

CPU stands for… and is composed off …
It’s composed of 2 types of storage: …

A

Central processing unit
Control unit and arithmetic logic unit (ALU)
primary and secondary unit

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

3 coding components

A

Sequence of instructions
Control of flow
A way to stop

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

Algorithm

A

Step by step instructions on how to complete a task

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

Program

A

A set of instructions represented in the form of a programming language

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

int represents … and common uses are …

A

whole numbers (-2, 0, 2)
counting purposes

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

float represents … and common uses are …

A

real numbers (3.14)
numeric calculations

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

str represents … and common uses are …

A

sequence of characters (“hello”)
keys, input/output

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

bool represents … and common uses are …

A

true or false
control flow in programs

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

NoneType represents … and common uses are …

A

(None)
return type of a function that appears to not return anything

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

**

A

power

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

*

A

multiplication

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

/

A

division

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

+

A

addition

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

-

A

subtraction

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

%

A

modulus

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

Can ints and floats be mixed in arithmetics?

A

Yes, python will automatically convert int to float if needed

18
Q

== vs =

A

== is an equality operator, compares 2 values, returns true if values are equal
= is an assignment operator, used to assign a value to a variable not compare

19
Q

!=

20
Q

< / >

A

smaller / larger than

21
Q

<= / >=

A

smaller than / larger than or equal to

22
Q

== / != / < / > / <= / >= return … values

A

boolean (true / false)

23
Q

boolean operators

A

and (returns true if all values are true), or (returns true if at least 1 value is true)

24
Q

Any … of some type is evaluated to true when we use bool ()
print (bool (“Text”)) –>
print (bool (“”)) –>
print (bool (102)) –>
print (bool (0)) –>

A

non-empty or non-zero value
True
False
True
False

25
Strings are ... objects
non-scalar
26
type function is ...
a built in function that takes an object as input and returns what type it is (e.g. string)
27
print("Apples" == "apples") --> print("Apples" < "apples”) --> print("Apples" > "apples") -->
False True False ASCII converts letter to numbers and A lower than a
28
lexical order
the arrangement of a set of items with a recursive algorithm, such as the entries in a a dictionary whose order depends on their first letter unless these are the same in which case it is the second which decides, and so on
29
str has a length corresponding to ...
the number of characters in the sequence
30
the len() function ...
Checks the length of the function
31
name = "Python" print(name[0]) print(name[1]) print(name[2]) print(name[3]) print(name[4]) print(name[5]) print("Value of name is: ", name) print("Memory ID of name is: ", id(name)) name = "C++" print("Value of name is: ", name) print("Memory ID of name is: ", id(name))
P y t h o n Value of name is: Python Memory ID of name is: 140487979014320 Value of name is: C++ (reassigment) Memory ID of name is: 140487979638192
32
Are primitive data types (such as a string) mutable or immutable?
immutable
33
An object is considered mutable if ... and immutable if ...
its state or value can be modified after it is created its value cannot be changed after it has been created
34
Trying to change Hello to Hallo (e to a) str1 = "Hello" str1[1] = ”a" Would return ... because
TypeError: 'str' object does not support item assignment because string is immutable Would need to reassign string from Hello to Hallo Strings can"t be broken in parts
35
Define helper function
Define helper function from pytest import approx def error_message(actual, expected): return f'Actual {actual} != Expected {expected}'
36
primitive data types you bind them to a variable
int, float, bool, None, string
37
what function accesses the memory address of an object
id()
38
what function converts memory address to hex code
hex()
39
what operator compares whether 2 variables point to the same memory id
is
40
f you want to access the value of more than one index, you can use
[index_start : index_end] where index_start and index_end are integers Note that this will give you the values starting from index_start and until index_end - 1
41
what function sorts strings by their lexical order
sorted()