Quiz 2 Endg 233

0.0(0)
studied byStudied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/102

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 12:02 PM on 10/17/23
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

103 Terms

1
New cards

String

Sequence of characters that can be stored in a variable

2
New cards

String literal

string value specified in the source code of a program

3
New cards

Give an example of a string literal

any text in between quotation marks

4
New cards

The string type is a special construct known as a

sequence type

5
New cards

What is a sequence type

A type that specifies a collection of objects ordered from left to right

6
New cards

What is the index position of a string

The first character is at index 0, the second character is at index 1

7
New cards

How are strings assigned?

Strings can be assigned to variables just like other data types. For example, str1 = 'Hello' or str1 = str2

8
New cards

What is an Empty String?

An empty string is a sequence type with 0 elements, created using two quotes (e.g., my_str = '').

9
New cards

How do you find the length of a string?

The len() function is used to find the length (number of characters) of a string.

10
New cards

What does the len() function do?

It finds the number of characters in a string

11
New cards

How do you access characters in a string?

Index Positions, variable[index], —> this accesses the characters from left to right, negative numbers access characters from the right

12
New cards

What is String Concatenation?

It combines strings together (***without adding spaces)

13
New cards

What would ‘New’ + ‘York’ result in?

‘NewYork’

14
New cards

Are strings mutable?

Strings are immutable they cannot be changed in place. Instead a new string is created each time.

15
New cards

How do you make changes to a string if its immutable?

You create a new string with the desired modifications

16
New cards

What is an empty string

string with 0 characters, they are used as placeholders

17
New cards

Can you change individual characters in a string in Python? Why or why not?

No, you cannot change individual characters in a string in Python. Strings are immutable, meaning that once created, they cannot be altered in place. If you want to change a string, you create a new string with the desired modifications.

18
New cards

Unicode

Unicode is a character encoding standard that assigns a unique number (code point) to every possible character, including letters, numbers, symbols, and more. Python uses Unicode to represent characters as code points, allowing it to work with a wide range of characters from different languages and scripts.

19
New cards

Code Point

numerical value that represents a specific character in the Unicode standard

20
New cards

Escape Sequence

two item sequence in a string that represents a special character using a backlash followed by a specific character

21
New cards

What is \n

newline

22
New cards

\\

backslash

23
New cards

\’

single quote

24
New cards

\”

double quote

25
New cards

How do you create a raw string?

add an r before a string literal

26
New cards

Give an example of formatting a raw string

r’text’

27
New cards

What do raw strings do

escape sequences are treated as literal characters, not interpreted

28
New cards

what does the ord() function do?

returns the encoded integer value for a string of length one—> helpful in finding the numerical encoding of a character

29
New cards

what does the chr() function do

it returns a string of one character for an encoded integer —> you can convert an encoded value back into a character

30
New cards

What does ‘Jen\nJoe\\nMaya\\\nAlex’

Jen

Joe\nMaya\

Alex

31
New cards

What is a formatted string literal / f-string?

allows a programmer to create a string with placeholder expressions that are evaluated as the program executes

32
New cards

How do you start a formatted string?

f’blahblah’

33
New cards

What does the equal sign do in an f-string

it prints both the expression and the result Ex: f'{2*4=}' produces the string "2*4=8".

34
New cards

What do double braces do in an f-string?

They place a curly brace x: f'{{Jeff Bezos}}: Amazon' produces the string "{Jeff Bezos}: Amazon".

35
New cards

What does format specification inside a repacement field do?

Allows a values formatting in the string to be customized

36
New cards

How is a format specification introduced inside a replacement field

a colon is used to separate the WHAT from the HOW Ex: {4:.2f} formats 4 as 4.00.

37
New cards

What does a presentation type do in a format specification

determines how to represent a value in text form, such as an integer (4), a floating point (4.0), a fixed precision decimal (4.000), a percentage (4%), a binary (100), etc.

38
New cards

what does the format specification :s do?

string(can be omitted as it is defult)

39
New cards

what does the format specification :d do?

decimal(integer values only) 12:03d —> 012

40
New cards

what does the format specification :b do?

binary(integer values only)

41
New cards

what does the format specification :x/X do?

Hexadecimal in lowercase(x) and upper case(X) int values only

42
New cards

what does the format specification :e do?

exponent notation (e to the___)

43
New cards

what does the format specification :f do?

fixed point notation(six places of precision)

44
New cards

what does the format specification :.[precision]f do?

fixed-point notation(you can specify how many decimals!

45
New cards

what does the format specification :0[precision]d do?

leading 0 notation —> 4:03d would be 004

46
New cards

What is a container

construct used to group related values together and contains references to other objects instead of data

47
New cards

What is a list

a container created by surrounding a sequence of variables or literals with brackets [ ].

48
New cards

What is a list item called

An element

49
New cards

the index in a list

starts with 0

50
New cards

How do you access a specific item in a list

listname[index]

51
New cards

Are lists mutable?

Lists are mutable so, you can update list elements

52
New cards

How do you add an element to a list

list.append(value)

53
New cards

How do you remove an element from a list

list.pop(i) —> removes the element at index i from list

list.remove(value) —> removes the first element that is value

54
New cards

len(list)

length of list

55
New cards

list1+list2

Produce a new list by concatenating list2 to the end of list1.

56
New cards

min(list)

Find the element in the list with the smallest value. All elements must be of the same type

57
New cards

max(list)

Find the element in the list with the largest value. All elements must be of the same type.

58
New cards

sum(list)

Find the sum of all elements of a list (numbers only).

59
New cards

list.index(val)

Find the index of the first element in the list whose value matches val.

60
New cards

list.count(val)

Count the number of occurrences of the value val in the list.

61
New cards

Define tuple

stores a collection of data, like a list, but is immutable. supports len, indexing and other sequence functions

62
New cards

how is a tuple generated

creating a list of csv like (5,15,30)

63
New cards

When is a tuple used

Used when context of values is known ex latitude and longitude are always in a specific order

64
New cards

What is a set, and what are its properties

A set is an unordered collection of unique elements

  • Elements are unordered: Elements in the set do not have a position or index.

  • Elements are unique: No elements in the set share the same value.

65
New cards

What does the set() function do

it accepts a sequence-type iterable object(list, tuple,string)

66
New cards

How do you make a set literal?

{value,val,v} same can be done with set([1,2,3])

67
New cards

What happens if you pass a list into set()

it causes any duplicates to be omitted in the created set

68
New cards

What happens if you try to access an index in a set

RUNTIME error, there is no order!

69
New cards

What does remove() and pop() do to a set

removes a specific value, pop removes a random value

70
New cards

len(set)

number of elements in a set

71
New cards

set1.update(set2)

adds the elements in set2 to set1

72
New cards

set.add(value)

adds value into the set

73
New cards

set.remove(value)

removes value from the set

74
New cards

set.clear()

clears all elements from the set

75
New cards

set.intersection(a,b,c)

Returns a new set containing only the elements in common between set and all provided sets.

76
New cards

set.union(set_a, set_b, set_c...)

Returns a new set containing all of the unique elements in all sets.

77
New cards

set.difference(set_a, set_b, set_c...)

Returns a set containing only the elements of set that are not found in any of the provided sets.

78
New cards

set_a.symmetric_difference(set_b)

Returns a set containing only elements that appear in exactly one of set_a or set_b

79
New cards

Dictionaries include

Key:Value Pairs

80
New cards

curly braces to surround key:value pairs

createes dictionary contents

81
New cards

How to access dictionary entries

dictionary[key]

82
New cards

dict[k] = v

Adds a new key-value pair

83
New cards

del dict[k]

deletes value

84
New cards

Sequence types include

string, list, and tuple are containers for collections of objects ordered by position in the sequence

85
New cards

Mapping Type includes

dict type

86
New cards

Which types are immutable

tuple

87
New cards

Is a list invalid if it has multiple types?

No

88
New cards

Do dictionaries use the append function?

No

89
New cards

What is the syntax for tuples

parentheses

90
New cards

What is a membership operator

in and not in operators which yield True or False. Can be used to check if a string is a substring

91
New cards

Membership in dictionary

implies that a specific key exists in the dictionary, does not return value

92
New cards

What is an implicit conversion

type conversion automatically made by interpreter5.5

93
New cards

While loop

A while loop is a construct that repeatedly executes an indented block of code (known as the loop body) as long as the loop's expression is True.

94
New cards

sentinel value

a value that when evaluated by the loop expression causes the loop to terminate.

95
New cards

For loop

loops over each element in a container one at a time, assigning a variable with the next element that can then be used in the loop body.

96
New cards

How do you iterate a for loop backwards

for name in reversed(list)

97
New cards

range(Y)

sequence of all non-negative integers less than Y

98
New cards

range(X,Y)

Sequence of integers >=X and less than Y

99
New cards

range(X,Y,Z)

>=X and <Y, incrementing by Z

100
New cards

When should you use a for loop

when the number of iterations is computable or when accessing the elements of a container