Keywords and built-in functions
Precap
In comparison to a naturally spoken language the number of pre-defined words is quite small: 104 instead of thousands and most of the time You’ll probably use only around 30.
The tables below list all 35 keywords and 69 built-in functions in Python 3 and also show the differences between Python 2 and Python 3 (right now it is only important that the number is quite small and not how You can use them).
Keywords
Python 3 has 35 keywords. They cannot be used as an identifier (e.g. as name for a variable, function, or class – whatever those might be is not important now).
Python 2 & 3 |
Python 2 only |
Python 3 only |
||
|---|---|---|---|---|
29 keywords |
+2 |
+6 |
||
and |
except |
not |
exec |
False |
as |
finally |
or |
None |
|
assert |
for |
pass |
True |
|
break |
from |
raise |
async |
|
class |
global |
return |
await |
|
continue |
if |
try |
nonlocal |
|
def |
import |
while |
||
del |
in |
with |
||
elif |
is |
yield |
||
else |
lambda |
|||
The following 24 keywords are the most likely ones You’ll frequently use (without going into detail now):
- False, True
The two possible values of the Boolean data type.
- None
The representation of the absence of a value.
- and, or, not
The three Boolean operators.
- if, elif, else
Conditional code execution.
- for, range, while, break, continue, else
Repeated code execution (loops).
- def, return
Reusable code (functions).
- class
Reusable, object orientated code.
- try, except, finally
Error handling.
- from, import, as
Using modules from other libraries (= code that saves You time because somebody else, who had the same task, already wrote it).
Built-in Functions
Python 3 has 69 built-in functions which are always available (there are also functions that are only available in certain situations).
Python 2 & 3 |
Python 2 only |
Python 3 only |
||
|---|---|---|---|---|
65 built-in functions |
+11 |
+4 |
||
abs() |
globals() |
ord() |
basestring() |
ascii() |
all() |
hasattr() |
pow() |
cmp() |
breakpoint() |
any() |
hash() |
print() |
execfile() |
bytes() |
bin() |
help() |
property() |
file() |
exec() |
bool() |
hex() |
range() |
long() |
|
bytearray() |
id() |
repr() |
raw_input() |
|
callable() |
input() |
reversed() |
reduce() |
|
chr() |
int() |
round() |
reload() |
|
classmethod() |
isinstance() |
set() |
unichr() |
|
compile() |
issubclass() |
setattr() |
unicode() |
|
complex() |
iter() |
slice() |
xrange() |
|
delattr() |
len() |
sorted() |
||
dict() |
list() |
staticmethod() |
||
dir() |
locals() |
str() |
||
divmod() |
map() |
sum() |
||
enumerate() |
max() |
super() |
||
eval() |
memoryview() |
tuple() |
||
filter() |
min() |
type() |
||
float() |
next() |
vars() |
||
format() |
object() |
zip() |
||
frozenset() |
oct() |
__import__() |
||
getattr() |
open() |
|||
The following 9 built-in functions are the most likely ones You’ll frequently use (without going into detail now):
- abs()
Calculates the absolute value of a number
- float(), int(), str()
Converts one data type to another.
- len()
Returns the length of an element (e.g. a text or list).
- print()
Outputs text.
- range()
Returns an iterator (= creates a sequence of numbers to be used in loops).
- dir(), type()
Returns information about an element.