Unit 1 (PPS)
Unit 1 (PPS)
Function Description
delattr() Deletes the specified attribute (property or method) from the
specified object
class Person:
name = "John"
age = 36
country = "Norway"
delattr(Person, 'age')
Function Description
delattr() Deletes the specified attribute (property or method) from the
specified object
Syntax
class Person:
name = "John" delattr(object, attribute)
age = 36
country = "Norway"
delattr(Person, 'age')
Function Description
dict() Returns a dictionary (Array)
print(x)
OUTPUT:
{'name': 'John', 'age': 36, 'country':
'Norway'}
Python Built in Functions
Function Description
dir() Returns a list of the specified object's properties and methods
Function Description
divmod() Returns the quotient and the remainder when argument1 is
divided by argument2
OUTPUT:
x = divmod(5, 2)
(2, 1)
print(x)
Python Built in Functions
Function Description
enumerate() Takes a collection (e.g. a tuple) and returns it as an enumerate
object
OUTPUT:
[(0, 'apple'), (1, 'banana'), (2,
'cherry')]
Python Built in Functions
Function Description
enumerate() Takes a collection (e.g. a tuple) and returns it as an enumerate
object
OUTPUT:
[(0, 'apple'), (1, 'banana'), (2,
'cherry')]
Python Built in Functions
Function Description
eval() Evaluates and executes an expression
Function Description
exec() Executes the specified code (or object)
Function Description
exec() Executes the specified code (or object)
Function Description
exec() Executes the specified code (or object)
adults = filter(myFunc, ages)
for x in adults:
print(x)
Python Built in Functions
Function Description
float() Returns a floating point number
x = float(3)
print(x)
OUTPUT:
3.0
Python Built in Functions
Function Description
format() Formats a specified value
x = format(0.5, '%')
print(x)
OUTPUT:
50.000000%
Python Built in Functions
Function Description
getattr() Returns the value of the specified attribute (property or method)
country = "Norway"
x = getattr(Person, 'age')
print(x)
Python Built in Functions
Function Description
hex() Converts a number into a hexadecimal value
x = hex(255) OUTPUT:
print(x) 0xff
Python Built in Functions
Function Description
id() Returns the id of an object
print(y)
Function Description
input() Allowing user input
Function Description
int() Returns an integer number
x = int(3.5) OUTPUT:
print(x) 3
Python Built in Functions
Function Description
iter() Returns an iterator object
print(next(x)) apple
banana
print(next(x)) cherry
print(next(x))
Python Built in Functions
Function Description
len() Returns the length of an object
x = len(mylist) 3
print(x)
Python Built in Functions
Function Description
list() Returns a list
print(x)
['apple', 'banana', 'cherry‘]
Python Built in Functions
Function Description
max() Returns the largest item in an iterable
Function Description
min() Returns the smallest item in an iterable
Function Description
oct() Converts a number into an octal
x = oct(12) OUTPUT:
print(x) 0o14
Python Built in Functions
Function Description
pow() Returns the value of x to the power of y
x = pow(4, 3) OUTPUT:
print(x) 64
Python Built in Functions
Function Description
print() Prints to the standard output device
OUTPUT:
Python Built in Functions
Function Description
print() Prints to the standard output device
OUTPUT:
Python Built in Functions
Function Description
range() Returns a sequence of numbers, starting from 0 and increments by
1 (by default)
OUTPUT:
x = range(6) 0
1
for n in x: 2
3
print(n)
4
5
Python Built in Functions
Function Description
reversed() Returns a reversed iterator
OUTPUT:
print(x)
Python Built in Functions
Function Description
round() Rounds a numbers
OUTPUT:
x = round(5.76543, 2) 5.77
print(x)
Python Built in Functions
Function Description
round() Rounds a numbers
OUTPUT:
x = round(5.76543, 2) 5.77
print(x)
Python Built in Functions
Function Description
set() Returns a new set object
print(x) OUTPUT:
# Note: the set list is unordered, so the result {'banana', 'cherry', 'apple'}
name = "John"
OUTPUT:
age = 36
40
country = "Norway"
x = getattr(Person, 'age')
print(x)
Python Built in Functions
Function Description
slice() Returns a slice object
OUTPUT:
a = ("a", "b", "c", "d", "e", "f", "g", "h")
(‘a’, ‘b’)
x = slice(2)
print(a[x])
Python Built in Functions
Function Description
sorted() Returns a sorted list
OUTPUT:
a = ("b", "g", "a", "d", "f", "c", "h", "e")
x = sorted(a) ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
print(x)
Python Built in Functions
Function Description
str() Returns a string object
OUTPUT:
x = str(3.5)
3.5
print(x)
Python Built in Functions
Function Description
sum() Sums the items of an iterator
OUTPUT:
a = (1, 2, 3, 4, 5)
x = sum(a) 15
print(x)
Python Built in Functions
Function Description
tuple() Returns a tuple
OUTPUT:
x = tuple(("apple", "banana", "cherry"))
('banana', 'cherry', 'apple')
print(x)
Python Built in Functions
Function Description
type() Returns the type of an object
print(x)
print(y)
print(z)
Python Built in Functions
Function Description
zip() Returns an iterator, from two or more iterators
print(tuple(x)) OUTPUT: