Module 2.3 Data Types

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

1/44

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

45 Terms

1
New cards

Strings

A sequence of characters that can be stored in a variable

2
New cards

String Literal

String value specified in the source code of the program

E.g. “class”, “python”, “this is a string!”

3
New cards

input()

gives the user a prompt and then reads in a string from the user

4
New cards

len()

s a built-in function that can be used to find the length of a string (and any other sequence type)

5
New cards

String Concatenation

A program can add new characters to the end of a string

6
New cards

Container

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

7
New cards

List

A container created by surrounding a sequence of variables or literals within brackets []

8
New cards

Element

an item in a list

9
New cards

Index

contained elements in a list are ordered by position within the list, starting with 0
are mutable — can be changed

10
New cards

Sequence-type Functions

knowt flashcard image
11
New cards

Tuples

An immutable container, which means the elements within can’t be changed

Sequence type structure that supports sequence functions such as len(), indexing, etc.

Is created using parenthesis

useful to ensure values are not changed when specified

12
New cards

Set

an unordered collection of unique elements

13
New cards

set()

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

14
New cards

Set literal

written using { } with elements separated by commas

e.g. integers_set = {1, 2, 3, 4, 5}

15
New cards

Mutable Sets (add/remove elements)

knowt flashcard image
16
New cards

Set Operations

knowt flashcard image
17
New cards

Dictionary

Python container used to describe associative relationships

Associates keys with values

18
New cards

Key

Term that can be located in a dictionary

Must be unique

19
New cards

Value

describes some data associated with a key and can be duplicated

20
New cards

Key-value pairs

keys need to be immutable types such as numbers, strings, or tuples, while a value can be any type

21
New cards

Dictionary Example

favorite_basketball_playes = {‘Lebron James’: 6, ‘Stephen Curry’: 30}

Keys: ‘Lebron James’ and ‘Stephen Curry’

Values: 6 and 30

22
New cards

Type Conversions

conversion of one type to another, such as an int to a float

23
New cards

Implicit Conversion

a type conversion automatically made by the interpreter, usually between numeric types

The result of an arithmetic operation like + or * will be a float only if either operand of the operation is a float

24
New cards

Conversion Functions

knowt flashcard image
25
New cards

Binary Number

Each memory location is composed of bits (0s and 1s), a processor stores a number using base 2

<p>Each memory location is composed of bits (0s and 1s), a processor stores a number using base 2</p>
26
New cards

Decimal Number

Numbers represented in base 10, where each digit must be 0-9 and each digit’s place is weighed by increasing powers of 10

<p>Numbers represented in base 10, where each digit must be 0-9 and each digit’s place is weighed by increasing powers of 10</p>
27
New cards

format()

A function that allows the programmer to create a string with placeholders that are replaced by values or variable values at execution

28
New cards

Replacement field

A placeholder surrounded by curly braces

29
New cards

String Formatting Example

Values inside the format() parentheses are inserted into the replacement fields in the string

<p>Values inside the format() parentheses are inserted into the replacement fields in the string</p>
30
New cards

Formatting Strings

knowt flashcard image
31
New cards

Which of the following are NOT data type names in Python?

Math ; String ; while ; double ; char ; if

32
New cards

Which of the following are data type names in Python?

float ; int ; str ; bool

33
New cards

Match the literal value to its python data type.

1, 1.0, False, “integer”

1 - int

1.0 - float

False - bool

“integer” - str

34
New cards

Match the literal value to its python data type.

123, 22.5, True, “round”

123 - int

22.5 - float

True - bool

“round” - str

35
New cards

Which of the following would be the best data type for a variable to store a friend's name?

str

36
New cards

A chef would like to record the number of guests that visit his restaurant in a day. Which data type would best represents this quantity?

int

37
New cards

Consider the following sequence of instructions:

a = 2 + 2
b = a * 2
a = b - 2
x = a * b

x

What will the variable x evaluate to on the last line?

48

38
New cards

What will the variable x evaluate to on the last line?

x = 1
y = 8
x = y + 1
y = x - 1
x = x + 1
y = y - 1
x = x - y
 
x

3

39
New cards

What will the variable x evaluate to on the last line?

x = 15
y = 3
x = x + 1
y = y - 1
x = x + y
 
x

18

40
New cards

What will the variable x evaluate to on the last line?

a = 16
x = a + 16
a = 8
 
x

32

41
New cards

Which of the following would be the best data type for a variable to store an alpha-numeric serial number?

str

42
New cards

A physician would like to record the heights of his patients in meters. Which data type would best represents this quantity?

float

43
New cards

Consider the following sequence of instructions:

a = 2 + 3
b = a - 5
a = a + 2
x = a * b

x

What will the variable x evaluate to on the last line?

0

44
New cards

What will the variable x evaluate to on the last line?

x = 8
y = 11
x = x + 1
y = y - 1
x = x + y
 
x

19

45
New cards

What will the variable x evaluate to on the last line?

x = 4
y = 6
x = y + 1
y = x - 1
x = x + 1
y = y - 1
x = x - y
 
x

3