Python Built-in Functions
In Python, built-in functions are functions that are always available for use without needing to import any libraries or modules
1. print()
1
print("Hello, world!") # Outputs: Hello, world!
2. len()
1
2
fruits = ["apple", "banana", "cherry"]
print(len(fruits)) # Outputs: 3
3. type()
1
2
age = 25
print(type(age)) # Outputs: <class 'int'>
4. int()
, float()
, str()
1
2
3
4
x = "5"
print(int(x)) # Converts to integer: 5
print(float(x)) # Converts to float: 5.0
print(str(10)) # Converts to string: '10'
5. input()
1
2
3
# name = input("Enter your name: ")
# print("Hello, " + name)
# (You have to run this in a terminal or script to see the interaction)
6. range()
1
2
for i in range(3):
print(i) # Outputs: 0 1 2
7. sum()
1
2
numbers = [1, 2, 3, 4]
print(sum(numbers)) # Outputs: 10
8. max()
/ min()
1
2
3
values = [4, 8, 1, 9]
print(max(values)) # Outputs: 9
print(min(values)) # Outputs: 1
9. abs()
1
2
n = -7
print(abs(n)) # Outputs: 7
10. round()
1
2
pi = 3.14159
print(round(pi, 2)) # Outputs: 3.14
11. sorted()
1
2
nums = [5, 2, 9, 1]
print(sorted(nums)) # Outputs: [1, 2, 5, 9]
This post is licensed under
CC BY 4.0
by the author.