Why do I need double = to define my city location?


#1

def plane_ride_cost(city):
if city == "Charlotte":
return 183
elif city == "Tampa":
return 220
elif city == "Pittsburgh":
return 222
elif city == "Los Angeles":
return 475

Why can't I just use
if city = "Charlotte"

A single equal sign did not work for my function. Why not? I thought the double == is used in mathematics.


#2

A single = is used only in assignments, not comparisons. In Python, == is a comparison operator that checks for identity, both of value and of type.


#3

Thank you so much mtf :smiley:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.