CS50P- Introduction to Python Flashcards

1
Q

What is a Sequence?

A

A sequence is a generic term for an ordered set (strings, lists, tuples, bytes, arrays, ranged objects)

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

What is a String?

A

Lines of code surrounded by either single or double quotation marks that can be assigned to a variable using an equal sign (assignment indicator).

Assign a string “Hello” to the variable a, then print that variable:

a = “Hello”
print (a)

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

What is a list?

A

Lists are used to store multiple values in a single variable. Values do NOT have to be of the same type.

Assign a list to a single variable, then print that variable:
Var = [“Geeks”, “for”, “Geeks”]
print(Var)

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

What is an array?

A

An array is used to store multiple values in one single variable.
Array’s values must be of the same type.

Array example:
cars = [“Ford”, “Volvo”, “BMW”]

Notice that arrays use regular brackets.

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

What is a tuple?

A

Tuples are used to store multiple items in a single variable.
Tuples are just like lists, but they are INDEXED.
Tuples are indexed and UNchangeable.

thistuple = (“apple”, “banana”, “cherry”)
print(thistuple)

Notice that tuples use regular parenthesis.

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

What is a dictionary?

A

Dictionaries are used to store data values in key:value pairs.
A dictionary is a collection which is ordered, but changeable.
Does not allow duplicates.

thisdict = {
“brand”: “Ford”,
“model”: “Mustang”,
“year”: 1964
}
print(thisdict)

notice that dictionaries use braces (curly brackets).

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

How can you do a multi line string?

A

Use three quotation marks to start the string.

a = “"”Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.”””

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

What is a set?

A

A set is a way to store multiple items in a single variable. A set is unchangeable, unordered and unindexed.

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

What are floats?

A

Float stands for floating point number, and represents a value either positive or negative containing one or more decimals

the letter e can be used to represent “to the power of 10”

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