ICT Assignment, 20 Python Functions
ICT Assignment, 20 Python Functions
print()
input()
len()
type()
str()
int()
float()
range()
list()
max()
min()
sorted()
round()
abs()
pow()
split() (for stri
join() (for strin
append() (for li
remove() (for li
enumerate()
Use
Displays output to the console.
Gets input from the user.
Returns the length of an object (e.g., string, list).
Returns the data type of an object.
Converts an object to a string.
Converts a string or number to an integer.
Converts a string or number to a floating-point number.
Creates a sequence of numbers.
Creates a list from an iterable.
Returns the largest item in an iterable.
Returns the smallest item in an iterable.
Returns a new sorted list from an iterable.
Rounds a number to a specified number of decimal places.
Returns the absolute value of a number.
Raises a number to a power.
Splits a string into a list of substrings based on a delimiter.
Joins a list of strings into a single string using a specified delimiter.
Adds an element to the end of a list.
Removes the first occurrence of a value from a list.
Returns an enumerate object that yields tuples containing a count (from start) and the values yielded
Example
print("Hello, world!")
name = input("Enter your name: ")
my_list = [1, 2, 3]<br>print(len(my_list)) # Output: 3
number = 10<br>print(type(number)) # Output: <class 'int'>
number = 42<br>text = str(number)<br>print(text) # Output: "42"
text = "10"<br>number = int(text)<br>print(number) # Output: 10
text = "3.14"<br>number = float(text)<br>print(number) # Output: 3.14
for i in range(5):<br> print(i) # Output: 0 1 2 3 4
my_string = "hello"<br>my_list = list(my_string)<br>print(my_list) # Output: ['h', 'e', 'l', 'l', 'o']
numbers = [1, 5, 2, 9, 3]<br>print(max(numbers)) # Output: 9
numbers = [1, 5, 2, 9, 3]<br>print(min(numbers)) # Output: 1
numbers = [5, 2, 9, 1, 3]<br>sorted_numbers = sorted(numbers)<br>print(sorted_numbers) # Output: [1, 2, 3, 5, 9]
number = 3.14159<br>rounded_number = round(number, 2)<br>print(rounded_number) # Output: 3.14
x = -5<br>print(abs(x)) # Output: 5
result = pow(2, 3) # 2 raised to the power of 3<br>print(result) # Output: 8
text = "hello world"<br>words = text.split()<br>print(words) # Output: ['hello', 'world']
words = ['hello', 'world']<br>sentence = " ".join(words)<br>print(sentence) # Output: "hello world"
my_list = [1, 2, 3]<br>my_list.append(4)<br>print(my_list) # Output: [1, 2, 3, 4]
my_list = [1, 2, 3, 2]<br>my_list.remove(2)<br>print(my_list) # Output: [1, 3, 2]
fruits = ['apple', 'banana', 'orange']<br>for i, fruit in enumerate(fruits):<br> print(i, fruit)
s) # Output: [1, 2, 3, 5, 9]
# Output: 3.14