Built In Functions in Python
? Built-in Functions in Python
Python provides many built-in functions that perform common operations like mathematical calculations, type conversions, input/output handling, and more.
? Categories of Built-in Functions
1?? Mathematical Functions
print(abs(-10)) # 10 (Absolute value)print(pow(2, 3)) # 8 (2^3)print(round(3.14159, 2)) # 3.14 (Round to 2 decimals)print(max(10, 20, 5)) # 20 (Find max)print(min(10, 20, 5)) # 5 (Find min)2?? Type Conversion Functions
print(int(3.9)) # 3 (Convert float to int)print(float(5)) # 5.0 (Convert int to float)print(str(100)) # "100" (Convert int to string)print(list("abc")) # ['a', 'b', 'c'] (Convert string to list)print(tuple([1, 2, 3])) # (1, 2, 3) (Convert list to tuple)3?? String Handling Functions
s = "hello world"print(len(s)) # 11 (String length)print(s.upper()) # "HELLO WORLD" (Convert to uppercase)print(s.lower()) # "hello world" (Convert to lowercase)print(s.replace("hello", "hi")) # "hi world" (Replace word)print(s.split()) # ['hello', 'world'] (Split string into list)4?? Input/Output Functions
# Take user inputname = input("Enter your name: ") # Print outputprint("Hello,", name)# Print multiple valuesprint("Age:", 25, "Height:", 5.8, sep=", ")5?? Data Structure Functions
numbers = [3, 1, 4, 1, 5]print(sorted(numbers)) # [1, 1, 3, 4, 5] (Sort list)print(sum(numbers)) # 14 (Sum of list)print(any([False, True, False])) # True (Check if any value is True)print(all([True, True, False])) # False (Check if all values are True)6?? Object and Variable Handling
x = 10print(type(x)) # <class 'int'> (Get type)print(id(x)) # Get memory address7?? Functional Programming Functions
nums = [1, 2, 3, 4]# Apply function to each elementprint(list(map(lambda x: x * 2, nums))) # [2, 4, 6, 8]# Filter values based on conditionprint(list(filter(lambda x: x > 2, nums))) # [3, 4]? Summary
Python provides over 70 built-in functions, making programming easier and more efficient.
? Commonly Used Ones:
print(),input(),len(),max(),min(),sum()str(),int(),float(),list(),tuple()map(),filter(),sorted(),zip()
Do you need examples for a specific function? ?