[go: up one dir, main page]

0% found this document useful (0 votes)
12 views2 pages

CSC108H Fall 2023 Final Exam: Short Python Function/method Descriptions

The document provides a comprehensive list of built-in Python functions and methods, including their signatures and descriptions. It covers various data types such as numbers, strings, lists, dictionaries, and file handling. Each function is described with its parameters and return types, serving as a reference for Python programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

CSC108H Fall 2023 Final Exam: Short Python Function/method Descriptions

The document provides a comprehensive list of built-in Python functions and methods, including their signatures and descriptions. It covers various data types such as numbers, strings, lists, dictionaries, and file handling. Each function is described with its parameters and return types, serving as a reference for Python programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSC108H Fall 2023 Final Exam: Short Python function/method descriptions

__builtins__:
abs(x: object) -> object
Return the absolute value of x.
float(x: object) -> float
Convert x to a floating point number, if possible.
int(x: object) -> int
Convert x to an integer, if possible. A floating point argument will be truncated
towards zero.
len(x: object) -> int
Return the length of the list, tuple, dict, or string x.
max(iterable: object) -> object
max(a, b, c, ...) -> object
With a single iterable argument, return its largest item.
With two or more arguments, return the largest argument.
min(iterable: object) -> object
min(a, b, c, ...) -> object
With a single iterable argument, return its smallest item.
With two or more arguments, return the smallest argument.
open(name: str[, mode: str]) -> TextIO
Open a file. Legal modes are "r" (read) (default), "w" (write), and "a" (append).
print(value: object, ..., sep=' ', end='\n') -> None
Prints the values. Optional keyword arguments:
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
range([start: int], stop: int, [step: int]) -> list-like-object of int
Return the integers from start (inclusive) to stop (exclusive) with step
specifying the amount to increment (or decrement). If start is not specified,
the sequence starts at 0. If step is not specified, the values are incremented by 1.
str(x: object) -> str
Convert an object into its string representation.
sum(iterable: object) -> number
Return the sum of an iterable collection of numbers.
type(x: object) -> the object's type
Return the type of the object x.

dict:
D[k] --> object
Produce the value associated with the key k in D.
del D[k]
Remove D[k] from D.
k in D --> bool
Produce True if k is a key in D and False otherwise.
D.keys() -> list-like-object of object
Return the keys of D.
D.values() -> list-like-object of object
Return the values associated with the keys of D.
D.items() -> list-like-object of Tuple[object, object]
Return the (key, value) pairs of D, as 2-tuples.

file open for reading (TextIO):


F.close() -> None
Close the file.
F.read() -> str
Read until EOF (End Of File) is reached, and return as a string.
F.readline() -> str
Read and return the next line from the file, as a string. Retain any newline.
Return an empty string at EOF (End Of File).
F.readlines() -> List[str]
Return a list of the lines from the file. Each string retains any newline.
F.write(x: str) -> int
Write the string x to file F and return the number of characters written.
CSC108H Fall 2023 Final Exam: Short Python function/method descriptions

list:
x in L --> bool
Produce True if x is in L and False otherwise.
L.append(x: object) -> None
Append x to the end of the list L.
L.extend(iterable: object) -> None
Extend list L by appending elements from the iterable. Strings and lists are
iterables whose elements are characters and list items respectively.
L.index(value: object) -> int
Return the lowest index of value in L, but raises an exception if value does
not occur in S.
L.insert(index: int, x: object) -> None
Insert x at position index.
L.pop([index: int]) -> object
Remove and return item at index (default last).
L.remove(value: object) -> None
Remove the first occurrence of value from L.
L.reverse() -> None
Reverse the list *IN PLACE*.
L.sort() -> None
Sort the list in ascending order *IN PLACE*.

str:
x in s --> bool
Produce True if x is in s and False otherwise.
S.count(sub: str[, start: int[, end: int]]) -> int
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
S.endswith(S2: str) -> bool
Return True if and only if S ends with S2.
S.find(sub: str[, start: int[, end: int]]) -> int
Return the lowest index in S where substring sub is found, such that sub is
contained within S[start:end], or -1 if sub is not found in S[start:end].
Default value of start is 0 and end is len(S).
S.index(sub: str[, start: int[, end: int]]) -> int
Like S.find but raises an exception if sub does not occur in S[start:end].
S.isalpha() -> bool
Return True if and only if all characters in S are alphabetic
and there is at least one character in S.
S.isdigit() -> bool
Return True if all characters in S are digits
and there is at least one character in S, and False otherwise.
S.islower() -> bool
Return True if and only if all cased characters in S are lowercase
and there is at least one cased character in S.
S.isupper() -> bool
Return True if and only if all cased characters in S are uppercase
and there is at least one cased character in S.
S.lower() -> str
Return a copy of the string S converted to lowercase.
S.replace(old: str, new: str) -> str
Return a copy of string S with all occurrences of the string old replaced
with the string new.
S.split([sep: str]) -> List[str]
Return a list of the words in S, using string sep as the separator and
any whitespace string if sep is not specified.
S.startswith(S2: str) -> bool
Return True if and only if S starts with S2.
S.strip([chars: str]) -> str
Return a copy of S with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
S.upper() -> str
Return a copy of the string S converted to uppercase.

You might also like