0% found this document useful (0 votes)
20 views

ICT Assignment, 20 Python Functions

Computer assignment, writing 20 python functions

Uploaded by

bayansileshi5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

ICT Assignment, 20 Python Functions

Computer assignment, writing 20 python functions

Uploaded by

bayansileshi5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Function Nam

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy