Built-in Functions
Python has many useful built-in functions that can simplify some operations. For instance, these are the following:
min(x, y, ...)- minimum element ofx, y, ...max(x, y, ...)- maximum element ofx, y, ...abs(x)- absolute value of numberxround(x, n)- rounds numberxtondigitspow(x, n)- exponentiation (xto the powern).
For example, you may need to investigate the minimum price of certain list of prices after applying discounts. Or you may need to convert kilometers into miles without extra digits.
123456789# List of prices with discounts prices = [400*0.7, 345*0.8, 270*0.95, 320*0.85] # The lowest price print(min(prices)) # Distance in kilometers dist = 5762.4 # Converting into miles and rounding to 2 digits print(round(dist/1.609, 2))
Tack för dina kommentarer!
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Ställ mig frågor om detta ämne
Sammanfatta detta kapitel
Visa verkliga exempel
Fantastiskt!
Completion betyg förbättrat till 2.7
Built-in Functions
Svep för att visa menyn
Python has many useful built-in functions that can simplify some operations. For instance, these are the following:
min(x, y, ...)- minimum element ofx, y, ...max(x, y, ...)- maximum element ofx, y, ...abs(x)- absolute value of numberxround(x, n)- rounds numberxtondigitspow(x, n)- exponentiation (xto the powern).
For example, you may need to investigate the minimum price of certain list of prices after applying discounts. Or you may need to convert kilometers into miles without extra digits.
123456789# List of prices with discounts prices = [400*0.7, 345*0.8, 270*0.95, 320*0.85] # The lowest price print(min(prices)) # Distance in kilometers dist = 5762.4 # Converting into miles and rounding to 2 digits print(round(dist/1.609, 2))
Tack för dina kommentarer!