Strings, Lists, Dictionaries, Tuples, and Sets. Flashcards

1
Q

What are strings?

A

Strings are sequences of characters, using the syntax of either single quotes or double quotes:
Ex. ‘hello’, “Hello”, “I don’t do that”.

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

Because strings are ordered sequences it means we can use _______ or ________.

A

indexing, slicing.

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

Indexing allows you to grab a single character or a subsection of multiple characters of a ordered sequence?

A

a single character.

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

Slicing allows you to grab a single character or a subsection of multiple characters of a ordered sequence?

A

subsection of multiple characters of a string.

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

Give the syntax for indexing the last character of the string Hi = “Hello World”.

A

In: Hi[-1]

or the one liner: “Hello World”[-1].

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

Give the syntax to reverse the order of the string Hi = “Hello World” using slicing.

A

In: Hi[ : : -1]

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

True/False: Arithmetic can be applied to variables.

A

True, two methods that was given was catenation and string multiplication.

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

Describe what string catenation does.

A
String catenation uses slicing to grab a subsection of a string to transform into another string.
ex. 
In:    name = 'Sam' 
In:    last_letters = name[1: ]
Out: am
In:    'P' + last_letters
Out: Pam
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe what string multiplication does.

A
String multiplication multiplies a string.
ex.
In:    letter = 'z'
In:    letter*10
Out: 'zzzzzzzzzz'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

String interpolation, sticking variables into strings, was taught using two methods. The format method and f-string. Give a basic example of how to use format method.

A

Format method:
Ex1. print(‘The {2} {1} {0}’.format(‘fox’, ‘brown’, ‘quick’))
Ex2. name = ‘Carlos’
print(‘Hello, my name is {}’.format(‘name’))

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

String interpolation, sticking variables into strings, was taught using two methods. The format method and f-string. Give a basic example of how to use f-string method.

A

f-string method:
Ex1. name = ‘Carlos’
age = ‘35’
print(f’{name} is my name and I am {age} years old.’)

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

What are lists?

A

Lists are ordered sequences that can hold a variety of object types.

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

Since lists are ordered sequences, they support what three concepts?

A

Slicing, indexing and nesting.

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

Give a general syntax of indexing.

A

In: variable = data type
In: variable[index_number]
or
In: ‘data_type’[index_number] for strings only.

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

Give a general syntax of slicing.

A

In: variable = data type
In: variable[start:stop:step]
or
In: ‘data_type’[start:stop:step] for strings only.

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

What are dictionaries in python?

A

Dictionaries are unordered mappings for storing objects.

17
Q

What is the key difference between dictionaries and lists?

A

Dictionaries are unordered mappings so they cannot utilize functions like slicing, indexing and sorting; whereas lists are ordered sequences which can.

18
Q

___________ & ____________ are mutable, but ___________ are immutable.

A

Lists, dictionaries, tuples.

19
Q

When creating one of these data types, each data type uses a unique character to enclose their data. Strings use ___, lists use ___, dictionaries use ___, tuples use ___.
When recalling data though, they all use the same characters __.

A

’’, [], {}, (); []

20
Q

Tuples are similar to lists. The key difference is that tuples are __________.

A

immutable.

21
Q

What are sets?

A
Sets are unordered collections of unique elements. They give only one representation of multiple elements. 
Thus,
In:    list = [1,2,1,1,3,4,4,4]
In:    set(list)
Out: (1,2,3.4)
22
Q

What are booleans?

A

Booleans are operators that allow you to convey True or False statements.