CS50P- Introduction to Python Flashcards
What is a Sequence?
A sequence is a generic term for an ordered set (strings, lists, tuples, bytes, arrays, ranged objects)
What is a String?
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)
What is a list?
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)
What is an array?
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.
What is a tuple?
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.
What is a dictionary?
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 can you do a multi line string?
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.”””
What is a set?
A set is a way to store multiple items in a single variable. A set is unchangeable, unordered and unindexed.
What are floats?
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”