This topic concerns screen 8 of the first guided project in Python.
So just to make sure. Because this is a list, all lists are always automatically in string format?
Also, how would we know without looking what the format is for the price value (even though it’s in string format)? i.e. 0 int vs 0.0 float
android_final = []
ios_final = []
for app in android_english:
price = app[7]
if price == '0':
android_final.append(app)
for app in ios_english:
price = app[4]
if price == '0.0':
ios_final.append(app)
print(len(android_final))
print(len(ios_final))
In Python list may contain DataTypes like Integers, Strings, as well as Objects and list may be heterogenous, i.e. contain mixed types. So it is not automatically in string format.
>>> my_list = ['val1', 1, 3.15]
>>> type(my_list[0])
<class 'str'>
>>> type(my_list[1])
<class 'int'>
>>> type(my_list[2])
<class 'float'>
Also, because Python is Dynamically Typed, i.e. you can re-assign variable with different Data Type:
>>> a = 1
>>> type(a)
<class 'int'>
>>> a = 'test'
>>> type(a)
<class 'str'>
we do not know the value type without looking at it.
So, it’s your task as a programmer to make sure that your if
statements work correctly either through type conversions or through tests.