week 2 variables Flashcards

1
Q

variable

A

named storage spot (‘box’) that holds value assigned by three properties

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

three properties of a variable

A

name/identity, type, and value

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

int

A

single whole number, integer

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

real values/ floating

A

decimal (needs bigger ‘box’)

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

string

A

letter(s) “ “

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

boolean

A

true or false

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

type function
type()

A

determines type of variable, can be verified with print

i.e print(type(variable))

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

how many numbers can a variable store?

A

one, it can be altered through reassignment

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

defining strings

A

first = “Ada”
last = “Lovelace”

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

concatenating strings

A

full = first + last
full = “AdaLovelace”
-> no space

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

how do you add numbers to a string

A

convert num to string with str() function

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

len(char)

A

number of characters

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

user.lower()

A

lowercases all alphabets

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

indexing username[0]

A

returns first character, starts at 0

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

immutable

A

cant be changed, strings can’t be altered through indexing

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

username[7] = “i”

A

ERROR.

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

string slicing

A

lets you select sections of a string

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

my_str[0:9]

A

returns first 10 characters

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

my_str[10:-5]

A

does 5 indices after 10, including 10

so basically 10 11 12 13 14 15

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

my_str[8:]

A

everything after 8

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

my_str[:8]

A

everything before 8

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

my_str[:-1]

A

everything but last character

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

find(x)

A

returns the index of the first occurrence of string x

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

**

A

power sign

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

//

A

integer division, number without remainder

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

%

A

modulus, remainder

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

26 // 5

A

5

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

26 % 5

A

1

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

module

A

library in python that has list of functions

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

format()

A

used to format output specified in string before

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

print(“Total Cost: ${:.2f}”.format(cost))

A

formats the cost by adding a dollar sign and only including two numbers after the decimal point

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

incrementing

A

increasing a variable’s value by 1

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

identifiers

A

names used by a programmer for items, sequences of letters, numbers and underscore

34
Q

a identifier must start with…

A

letter or underscore, and its case-sensitive

35
Q

PEP 8

A

python enhancement proposal, which outlines the basics of python. it suggests identifiers should be lowercase with underscore between words

36
Q

object

A

represents a value and is automatically created by the interpreter when executing a line of code

37
Q

examples of objects

A

integers, strings, functions, lists, etc

38
Q

temporary versus permanent objects

A

print(2+2) is temp
x = 7 is permenant

39
Q

garbage collection

A

deleting unused objects to free memory space

40
Q

name binding

A

associating names with interpreter object

41
Q

properties of objects

A

value, type, and identity

42
Q

immutable types

A

integers and strings, they can only be reassigned in new objects

43
Q

id()

A

gives value of object identity

44
Q

print(id(‘ABC’))

A

create and print identity of a string

45
Q

floating point literal

A

written with fractional part even if its a whole number (like 0.0, 1.0, 9.0, etc)

46
Q

scientific notation

A

representing super large or small numbers in terms of e

47
Q

max floating point number

A

1.8e308

48
Q

min floating point number

A

2.3e-208

49
Q

overflow

A

when value is too large to be stored in memory allocated by interpreter

50
Q

float should be used for…

A

measured values (ex: temperature)

51
Q

int should be used for…

A

counted values (ex: students)

52
Q

when specifying format, python ___ last digit

A

rounds

53
Q

expression

A

combo of items like vars, literals, operators, and parenthesis, that evaluate to a value
ex: 2* (x + 1)

54
Q

literal

A

specific value in code (ex: 2)

55
Q

operator

A

symbol that preforms built-in calculation

56
Q

precedence rules

A

ordered standard mathematics.
PEMDAS
() first
** second
- negative third
* / % mult, div, and % fourth
+ - add, sub, fifth
evaluate left to right for equal precedence

57
Q

compound operators

A

shorthand to update variables

58
Q

age += 1

A

age = age + 1

59
Q

age -= 1

A

age = age - 1

60
Q

age *= 1

A

age = age * 1

61
Q

age /= 1

A

age = age / 1

62
Q

age %= 1

A

age = age % 1

63
Q

//

A

floor division, rounds down and returns integer

64
Q

5.0 // 2

A

2.0
if operand is float, returns float

65
Q

script

A

python program written in a file which is passed to python interpreter as input

66
Q

import

A

statement that makes module available for use

ex:
import math

67
Q

dot notation

A

used to access objects defined in module

68
Q

if module is universe
and variable is speed…

A

universe.speed

69
Q

when imported, ____ code in module executes

A

all

70
Q

math module

A

standard python module that supports advances mathematics operations

71
Q

function

A

list of statements that can be executed by referencing functions name

72
Q

function call

A

process of invoking function

73
Q

argument

A

item passed to a function

74
Q

unicode

A

code that represents every possible character as a unique number
ASCII

75
Q

code point

A

unique numbers in unicode

76
Q

escape char \

A

single backslash

77
Q

escape char '

A

single quote

78
Q

escape char "

A

double quote

79
Q

\t

A

tab/indent

80
Q

raw string

A

ignores the escape sequences, created by adding r before string literal

81
Q

ord()

A

returns encoded integer value for string of length 1
ex: ord(‘H’) returns 72

82
Q

chr()

A

returns string of one char for encoded int
ex: chr(72) returns ‘H’