CQS Final

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/219

encourage image

There's no tags or description

Looks like no tags are added yet.

220 Terms

1
New cards

Where code is entered

code cell

2
New cards

constant

fixed values, those which dont change ex. string, numeric

3
New cards

print()

displays data as the output

4
New cards

strings

sequence of characters

letters, words, numbers

anything encased in single or double quotes

5
New cards

numeric constants

doesnt need quotes

only numbers

6
New cards

comments and how they help

anything following a #, doesnt return an output

improve readability, usually explain code, best practice to use them

7
New cards

line spaces…

do not impact the code!

8
New cards

value

basic unit of a program a letter, number, or other

9
New cards

types of values

integer, str, float, bool, dict, tuple, list

10
New cards

dont type integers with ___

commas

11
New cards

float

numbers with a decimal point, even if its .00

12
New cards

bool

boolean, true or false

13
New cards

type()

returns the type of a value - int,str, float, bool, list, dict, tuple

returned as <class ‘type’>

14
New cards

float()

changes an integer/string to a float

only strings that work with floats are numbers

15
New cards

adding different types of values

int/float + string = ERROR
int + int = INT
float + float = FLOAT

int + float = FLOAT

16
New cards

variables

a named place that stores a value and can retrieve it later. variable can change

17
New cards

assignment statement

creates new variables and gives them values

only one =

ex. x = 2

18
New cards

type of a variable is….

the type it is assigned to

19
New cards

rules of variables name

  • cant start with a number (but can INCLUDE numbers)

  • cant contain special characters (@,!, a space)

  • cannot contain keyword/reserved words (False, class, continue, and)

  • are case sensitive! (age and AGE are different)

20
New cards

statement

unit of code that the python interpreter can execute

21
New cards

operators

special symbols that represent computations

22
New cards

list of operators and functions

/ = divides, always makes a float

+adds

-subtracts

*multiplies

//will divide then truncate float to an integer (floored division)

% yields remainder when first number divided by the second (modulus operator)

** exponent

23
New cards

multiple operators follow….

PEMDAS/operator precedence

24
New cards

string concatenation

joining strings by linking them end to end

use a + or can use *

25
New cards

operands

values operators applied to

26
New cards

expressions

combination of values, variables, and operators

(value all by itself is considered an expression)

27
New cards

input()

gets a value for a variables from the user

can pass prompt before entering with a string in ()

what the user enters is always a string

28
New cards

\n

represents newline, special character that represents a line break

29
New cards

comparison operators. list and meaning

compares two operand and returns either True or False

== equal?

!= not equal

> greater than

< less than

>= greater than or equal to

<= less than or equal to

“is”

“is not”

30
New cards

logical operators, list and function

and

  • only returns True if both statements are true

or

  • only returns true if either statement is true

not

  • negates boolean expression result

31
New cards

conditional execution

gives ability to check conditions and change behavior of program accordingly

ex. if (boolean):

function

32
New cards

boolean after an if statement known as ..

the condition

33
New cards

indentation portion after an if statement, else, try, etc.

the block, runs all statements in the block

34
New cards

if statements, try, etc are known as

compound statements, consist of more then one line

35
New cards

alternative execution

if (boolean):

function

else:

function

one alternative always executed, else never has conditional with it

alternatives known as branches

36
New cards

chain conditional

when more than 2 alternatives

if (boolean):

function

elif():

function

…..

else:

can have an infinite number of elifs

dont need an else statement, but if so should be at the end

37
New cards

nested conditions

when there is one condition within another

38
New cards

exception handling structure

used when we expect there to be an error in the program

Try:

any one which could create an error

Except:

what to do if there is an error

if try works, exception is skipped

39
New cards

two types of loops

indefinite and definite

40
New cards

indefinite loop

a while loop

indefinite # of iterations, until condition becomes False

iteration variable that changes each time with the loop

41
New cards

iteration

everytime we execute the body and come back to the beginning

42
New cards

iteration variable

the variable that changes with each time the loop executes and controls when it finishes

variable after for in the for loop is an example of an iteration variable

43
New cards

while loop set up and flow of execution

while (boolean):

function

  1. evaluate condition,yield true or false

  2. if false, exit while statement and continue at next statement

  3. if true, execute body and go back to step one

44
New cards

no iteration variable results in…

an infinate loop

45
New cards

break statement

forces the end of a loop

usually comes in an if statement as part of a while loop

46
New cards

continue statement

skips the rest of the body and begins the next iteration

47
New cards

definite loops

ends after a set known period of iterations. # of iterations = items in the set

for iteration variable in sequence:

function

iteration variable moves through all set values in the sequence

48
New cards

function

a named sequence of statements

49
New cards

format of a function

function()

that in () is the argument

return of a function is the return value

50
New cards

two types of functions

built in and those we define ourselves

51
New cards

built in function

those provided as part of python

ex. type(), float(), int()

treated as reserved words

52
New cards

max()

gives max number in a sequence

in a string, this is the letter with the highest value (a is low value and uppercase less than lower)

53
New cards

min

gives min number in a sequence

or in a string, letter with the lowest value (a is low value)

54
New cards

len()

returns the number of items in an argument

for a string, this would be the number of characters

for a list and tuple, number of values

for dict, number of key - value pairs

55
New cards

making your own function

def funtionname()

defines, but gives no output

56
New cards

calling a function

using a function outside where it was defined

57
New cards

parameter

the variable we use in the function definition. handle that lets the code in function access arguments passed to the function when it is called

58
New cards

return statement

gives the value of the function back to where it was called, if we call a function but dont a return a value - we will just get “none”

59
New cards

fruitful function

produces a result or return value

60
New cards

void function

no result, or return keyword

61
New cards

slice

a segment of a sequence

62
New cards

how to get one letter from a string

string/variable[index]

63
New cards

how does an index match to a string

index 0 = first letter of the string

64
New cards

how to get a segment of a string and rules

string/variable[index:index]

returns the left index but not the right

if second number beyond end, stops at the end

65
New cards

how to segment from beginning of string

string/variable[:index]

66
New cards

how to segment to end of string

string/variable[index:]

67
New cards

methods

functions built into the object itself and available to any instance of the object

68
New cards

string methods….

can only be used with strings

69
New cards

dir()

returns directory of all the methods which can be used with the object and the properties of the object

70
New cards

string.upper()

puts all in uppercase

71
New cards

string.lower()

puts all in lowercase

72
New cards

string.find(term)

checks to see if a term exists in an existing string

if found, returns the index of the firs occurrence of the string

if not found, returns -1

73
New cards

word.strip()

gets rid of all spaces on the left AND right

74
New cards

word.lstrip()

gets rid of all spaces on the left

75
New cards

word.rstrip()

 gets rid of all spaces on the right

76
New cards

string.replace(term to find, term to replace with)

find the term and puts in substitute

replaces all occurrences of the string

no error if it cant be found

77
New cards

list

a sequence of values

can include: dicts, tuples, integers, floats, strings, or other lists. all data types!

stored in a variable

78
New cards

values in a list

elements or items

separated by a coma

79
New cards

a list must be enclosed in

[]

80
New cards

2nd way to create a list

list()

81
New cards

way to access parts of a list

listname[index]

82
New cards

mutable types

lists and dictionaries

83
New cards

how to change a list

listname[index] = replacement value

84
New cards

list concaatenation

use +

prints the values from the first list, then the seconf

85
New cards

slicing a list from beginning

list_name[:index]

86
New cards

slicing a list

list_name[index:index]

87
New cards

slicing a list to the end

list_name[index:]

88
New cards

how to add items to end of list

list_name.append(term)

adds to list in order added

can repeat term

ONLY ADDS TO END, CANNOT PASS INDEX

can only append one item at a ti

89
New cards

how to sort a list

list_name.sort()

organizes numbers from low to high

if strings, goes in alphabetical order

90
New cards

how to sort a list in reverse

list_name.sort(reverse=True)

organizes numbers from high to low

if strings, goes in reverse alphabetical order

91
New cards

dictionary

a list, but more general. in {}. index dont have to be integers

92
New cards

key value pair

key- the “words” of the dictionary

value- the “meanings” of the words

aka as an item

93
New cards

creating a dictionary

dict()

or {} to a variable

94
New cards

adding items to a dictionary

dictname[newkey]=newvalue

95
New cards

keys can be….

strings or numbers

and CANNOT be repeated, will just update to the “last” instance

96
New cards

values can be…

any data type: strings, integers, floats, lists, dict, bool

duplicated as well!

97
New cards

accessing values in a dictionary

two methods

  1. dictname[keyname] also used for strings and list

  2. dictname.get(keyname) only for dict

    can get all values with, returns none if not there

  3. d.values()

98
New cards

traversing through keys of a dict in a loop

for key in dict:

print(key)

99
New cards

traversing through values of a dict in a loop, 2 methods

  1. for variable in dictname:

    print(dictname[variable]

  2. for variable in dictname.values():

    print(variable)

100
New cards

traversing through items/key value pairs in a loop. 3 methods

  1. for variable in dict:

    print(variable, dict[variable])

  2. for variable in dict.items():

    print(name)

    will return each as tuple

  3. for k,v in dict.items():

    print(k, ";”, v)