Built-in Functions
Only the required built-in functions for S1 are mentioned here.
bin
Converts an integer to a binary string.
chr
Returns the string representing a character for the given Unicode code.
complex
Creates a complex number.
dict
Creates a dictionary.
float
Converts a number or string to a float.
hex
Converts an integer to a hexadecimal string.
id
Returns the identity of an object.
int
Converts a number or string to an integer.
len
Used to return the number of items in an object. Commonly used with sequences (like lists, tuples, and strings) and collections (like dictionaries and sets).
max
Returns the largest item.
min
Returns the smallest item.
open
Opens a file and returns a file object. The open
function is fundamental for
file operations in Python.
Basic syntax: open(filename, mode='r', encoding=None)
Common modes:
'r'
: Read (default)'w'
: Write (overwrites)'a'
: Append'b'
: Binary mode
When with
statement is used, the file will be automatically closed after use.
If not, the file has to be closed using f.close()
.
ord
Returns the Unicode code for a given character.
pow
Returns the power of a number.
print
Prints to the console.
range
Used to generate a sequence of numbers. Commonly used in for
loops to iterate
over a sequence of numbers. The range
function can take 1, or 2, or 3
arguments, similar to
string slicing.
range(stop)
: Generates numbers from 0 tostop - 1
.range(start, stop)
: Generates numbers fromstart
tostop - 1
.range(start, stop, step)
: Generates numbers fromstart
tostop - 1
, incrementing bystep
.
Here are some examples:
The range
function returns an immutable sequence type, which can be converted
to a list if needed:
reversed
Returns a reversed iterator.
round
Rounds a number to a specified number of digits.
set
Creates a set.
str
Converts an object to a string.
sum
Returns the sum of a collection.
tuple
Creates a tuple.
type
Returns the type of an object.