Module 4 Flashcards
List all the built in data types in python
Integers - int
Floating-point numbers - float
Strings - str
Booleans -bool
Lists - list
Tuples - tuple
Sets - set
Dictionaries - dict
what data type is this ?
age = 6
type(age)
int
age = 6.0
type(age)
what data type ?
float
which value cannot be converted to any other type other than a float ?
NaN
What is NoneType ?
NoneType is its own type, with only one possible value, None.
which type has two values: True and False.
Boolean
name_of_bed_monster = ‘Mike Wazowski’
name_of_bed_monster
Which DT is this ?
string
If the string contains quotation marks or apostrophes, how do we declare those strings in python ?
we can use double quotes or triple single quotes, or triple-double quotes to define the string.
len()
returns the length of the string
.upper()
converts into upper case
.lower()
converts into lower case
count()
We can also count the number of times a substring or character is present in a string with .count().
float(‘five’)
output ?
ValueError: could not convert string to float: ‘five’
Detailed traceback:
File “<string>", line 1, in <module></module></string>
float(None)
output ?
TypeError: float() argument must be a string or a number, not ‘NoneType’
Detailed traceback:
File “<string>", line 1, in <module></module></string>
sentence = “I always lose at least one sock when I do laundry.”
words = sentence.split()
words
output ?
[‘I’, ‘always’, ‘lose’, ‘at’, ‘least’, ‘one’, ‘sock’, ‘when’, ‘I’, ‘do’, ‘laundry.’]
sentence = “I always lose at least one sock when I do laundry.” sentence.split(“e”)
output ?
This argument uses the character “e” to separate the string and discards the separator.
[‘I always los’, ‘ at l’, ‘ast on’, ‘ sock wh’, ‘n I do laundry.’]
What type of elements are present in a List ?
The elements in a list can be any objects, and they don’t all need to have the same type.
lists_of_lists = [[1,2], [‘buckle’, ‘My’, ‘Shoe’], 3, 4]
lists_of_lists
output ?
4
Lists vs strings
Lists are mutable whereas strings are not