Week 3: Types Flashcards

(17 cards)

1
Q

What is a string?

A

A sequence of characters that represents text data like a person’s name, location or a user message.

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

Strings:

Sequence Type

A

Objects in a string are ordered from first to last and the position of each character is indexed starting at 0 NOT 1.

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

len()

A

An operation that can be used to find the length of a string.

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

String Indexing

How can I access characters within the string? [ ]

A

If you need to reference a character at a specific index use [ ] with the index you need. Positive numbers take from the right, Negative numbers take from the left.

e.g. print(alphabet[19]) or alphabet[-26])

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

updating a string

String Concatenation

A

You can add new characters to the end of a string using addition.

e.g. city = New + York prints NewYork

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

Formatted strings

What are f-strings?

A

These are formatted strings that can be used in print statements to pull in multiple strings or add strings together.

number=6
amount = 32
print(f”{number} coffees cost ${amount}”)

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

List

A

This is a container that is created by putting a squence of variables together with [ ].

e.g. prices = [20, 14.99, 5]

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

List:

Element

A

An item in a lists. Lists are mutable so can be replaced, reordered or removed.

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

Adding or removing list elements:

Append()

A

This adds new elements to a list.

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

Adding or removing list elements:

pop(Index) OR remove(“element”)

A

Pop() removes the element at the desired index.

Remove() removes the first element that matches(“ “)

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

function & methods for lists:

Picture with common list functions

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

Tuple (toople)

A

Stores a collection of data like a list but is immutable, cannot be changed.

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

Set()

A

A set is an unordered collection of elements but is UNORDERED and UNIQUE.

Sets are mutable and elements can be removed or added.

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

Common set() operations - picture

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

Dictionaries

A

A container that shows associatve relationships using {key: value} pairs. You access them by calling the key like {players[‘Lionel Messi’]}

e.g. {“Lionel Messi”: 10}

16
Q

Data Types Summary Picture