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
//
integer division, number without remainder
26
%
modulus, remainder
27
26 // 5
5
28
26 % 5
1
29
module
library in python that has list of functions
30
format()
used to format output specified in string before
31
print("Total Cost: ${:.2f}".format(cost))
formats the cost by adding a dollar sign and only including two numbers after the decimal point
32
incrementing
increasing a variable's value by 1
33
identifiers
names used by a programmer for items, sequences of letters, numbers and underscore
34
a identifier must start with...
letter or underscore, and its case-sensitive
35
PEP 8
python enhancement proposal, which outlines the basics of python. it suggests identifiers should be lowercase with underscore between words
36
object
represents a value and is automatically created by the interpreter when executing a line of code
37
examples of objects
integers, strings, functions, lists, etc
38
temporary versus permanent objects
print(2+2) is temp x = 7 is permenant
39
garbage collection
deleting unused objects to free memory space
40
name binding
associating names with interpreter object
41
properties of objects
value, type, and identity
42
immutable types
integers and strings, they can only be reassigned in new objects
43
id()
gives value of object identity
44
print(id('ABC'))
create and print identity of a string
45
floating point literal
written with fractional part even if its a whole number (like 0.0, 1.0, 9.0, etc)
46
scientific notation
representing super large or small numbers in terms of e
47
max floating point number
1.8e308
48
min floating point number
2.3e-208
49
overflow
when value is too large to be stored in memory allocated by interpreter
50
float should be used for...
measured values (ex: temperature)
51
int should be used for...
counted values (ex: students)
52
when specifying format, python ___ last digit
rounds
53
expression
combo of items like vars, literals, operators, and parenthesis, that evaluate to a value ex: 2* (x + 1)
54
literal
specific value in code (ex: 2)
55
operator
symbol that preforms built-in calculation
56
precedence rules
ordered standard mathematics. PEMDAS () first ** second - negative third * / % mult, div, and % fourth + - add, sub, fifth evaluate left to right for equal precedence
57
compound operators
shorthand to update variables
58
age += 1
age = age + 1
59
age -= 1
age = age - 1
60
age *= 1
age = age * 1
61
age /= 1
age = age / 1
62
age %= 1
age = age % 1
63
//
floor division, rounds down and returns integer
64
5.0 // 2
2.0 if operand is float, returns float
65
script
python program written in a file which is passed to python interpreter as input
66
import
statement that makes module available for use ex: import math
67
dot notation
used to access objects defined in module
68
if module is universe and variable is speed...
universe.speed
69
when imported, ____ code in module executes
all
70
math module
standard python module that supports advances mathematics operations
71
function
list of statements that can be executed by referencing functions name
72
function call
process of invoking function
73
argument
item passed to a function
74
unicode
code that represents every possible character as a unique number ASCII
75
code point
unique numbers in unicode
76
escape char \\
single backslash
77
escape char \'
single quote
78
escape char \"
double quote
79
\t
tab/indent
80
raw string
ignores the escape sequences, created by adding r before string literal
81
ord()
returns encoded integer value for string of length 1 ex: ord('H') returns 72
82
chr()
returns string of one char for encoded int ex: chr(72) returns 'H'