TRAVEL
Click the Blue Words to Follow Us

Hello, everyone!~
Today we will learn about Python
Twenty essential functions
Let’s learn together!
1. print() – Outputs content to the console
print("hello, world!")
2. len() – Returns the length of a sequence object
fruits = ["apple", "banana", "cherry"]
print(len(fruits)) # Output: 3
3. input() – Gets input from the user
name = input("Please enter your name:")
print("Hello, " + name)
4. str() – Converts an object to a string
number = 10
print("The number is: " + str(number))
5. int() – Converts an object to an integer
age = int(input("Please enter your age:"))
print("Your age is: " + str(age))
6. float() – Converts an object to a float
pi = float("3.14")
print(pi)
7. range() – Returns a sequence of integers within a specified range
numbers = list(range(1, 6))
print(numbers) # Output: [1, 2, 3, 4, 5]
8. max() – Returns the maximum value
numbers = [5, 10, 3, 8]
print(max(numbers)) # Output: 10
9. min() – Returns the minimum value
numbers = [5, 10, 3, 8]
print(min(numbers)) # Output: 3
10. sum() – Returns the sum of elements in a sequence object
numbers = [1, 2, 3, 4, 5]
print(sum(numbers)) # Output: 15


11. abs() – Returns the absolute value of a number
print(abs(-10)) # Output: 10
12. round() – Rounds a number to the nearest integer
print(round(3.1415, 2)) # Output: 3.14
13. sorted() – Sorts a sequence object
numbers = [5, 2, 8, 3, 1]
print(sorted(numbers)) # Output: [1, 2, 3, 5, 8]
14. type() – Returns the type of an object
print(type("Hello")) # Output: <class 'str'>
15. str.upper() – Converts a string to uppercase
text = "hello"
print(text.upper()) # Output: HELLO
16. str.lower() – Converts a string to lowercase
text = "WORLD"
print(text.lower()) # Output: world
17. str.capitalize() – Capitalizes the first letter of a string
text = "hello world"
print(text.capitalize()) # Output: Hello world
18. str.split() – Splits a string into a list using spaces
text = "hello world"
print(text.split()) # Output: ['hello', 'world']
19. str.replace() – Replaces specified characters in a string
text = "hello world"
print(text.replace("world", "Python")) # Output: hell
20. list.append() – Adds an element to the end of a list
fruits = ["apple", "banana"]
fruits.append("cherry")
print(fruits) # Output: ['apple', 'banana', 'cherry']
END
This lesson ends here.
There are many more functions in Python.
Students interested can learn on their own online.
Looking forward to seeing you next time~
