59 Python Glossary of Terms You Must Know - DataFlair
59 Python Glossary of Terms You Must Know - DataFlair
2. >>>
This is the default prompt of the Python interactive shell. We have seen this a lot in our
examples.
3. …
The default prompt of the Python interactive shell when entering code under an indented
block or within a pair of matching delimiters. Delimiters may be parentheses, curly braces,
or square brackets.
This is also called the ellipsis object.
4. 2to3
While most of the applications existing today have their base in Python 2.x, the future
belongs to Python 3.x. But 2.x code isn’t completely compatible with 3.x. Interestingly, we
have a tool available that will help us convert Python 2.x code to Python 3.x.
2to3 handles the incompatibilities, detecting them by parsing the source and traversing the
parse tree. The standard library has this as lib2to3.
5. Abstract Base Class
An abstract base class provides a way to define interfaces. This way, it complements duck
typing. For this, we have the module abc. It introduces virtual subclasses (classes that are
recognized by isinstance() and issubclass(), but do not inherit from another class. Python
has several built-in ABCs for data structures (use the collections.abc module), numbers
(use the numbers module), or streams (use the io module). You can also import finders and
loaders (use the importlib.abc module). And to create our own ABCs, we use the abc
module.
6. Python Argument
An argument is a value we pass to a function or a method when calling it. In Python, we
have the following kinds of arguments:
a. Default Arguments
When defining a function, we can provide default values for arguments. This way, when we
call it without any missing arguments, the default values will fill in for them. Default
arguments can only follow non-default ones.
Hello, Ayushi
1. >>> sayhello()
Hello, User
b. Keyword Arguments Python
Keyword arguments pertain to calling a function. When we then call the function, we can
pass it arguments in any order.
return b-a
https://data-flair.training/blogs/python-glossary/ 1/8
3/26/2019 59 Python Glossary of Terms You Must Know - DataFlair
1. >>> subtract(3,2)
-1
1. >>> subtract(b=2,a=3)
-1
c. Arbitrary Arguments
When we don’t know how many arguments we’ll get, we use an asterisk to denote an
arbitrary argument.
return total
1. >>> sum_all(1,2,3,4)
10
1. >>> sum_all(1,2,3)
6
d. Positional Arguments Python
These are regular arguments that aren’t keyword arguments. Python Positional Argument
Example.
return a+b
1. >>> add(3,4)
7
We use a * before an iterable if we must pass it as an argument to a function.
1. >>> add(*(3,4))
7
For more on arguments to functions, read on Python Function Arguments.
7. Asynchronous Context Manager
ACM is an object that controls the environment observed in an async with statement. It
does so by defining __aenter__() and __aexit__().
https://data-flair.training/blogs/python-glossary/ 2/8
3/26/2019 59 Python Glossary of Terms You Must Know - DataFlair
.pyc files, we mentioned that bytecode is cached into them. This lets the files execute faster
the second time since they don’t need to recompile.
In essence, bytecode is like an intermediate language that runs on a virtual machine. This
virtual machine converts it into machine code for the machine to actually execute it on.
However, one bytecode will not run on a different virtual machine.
If you’re interested in finding out about bytecode instructions, you can refer to the official
documentation for the dis module.
18. Python Class
A class, in Python, is a template for creating user-defined objects. It is an abstract data
type, and acts as a blueprint for objects of a kind while having no values itself.
To learn how to create and use a class, refer to Classes in Python.
19. Coercion
When we carry out operations like 2+3.7, the interpreter implicitly converts one data type
to another. Here, it converts 2 to 2.0 (int to float), and then adds, to it, 3.7. This is called
coercion, and without it, we would have to explicitly do it this way:
1. >>> float(2)+3.7
5.7
20. Complex Number
A complex number is made of real and imaginary parts. In Python, we use ‘j’ to represent
the imaginary part.
1. >>> type(2+3.7j)
<class ‘complex’>
An imaginary number is a real multiple of -1(the imaginary unit). To work with complex
equivalents of the math module, we use cmath. For more on complex numbers, read up
on Python Numbers.
These Python Glossary terms are very important to know before you dive into learning
Python.
21. Context Manager
The context manager is an object that controls the environment observed in a with-
statement. It does so with the __enter__() and __exit__() methods.
22. Coroutine
A subroutine enters at one point and exits at another. A coroutine is more generalized, in
that it can enter, exit, and resume at many different points. We implement them with the
async def statement.
23. Coroutine Function
A coroutine function is simply a function that returns a coroutine object. We may define
such a function with the async def statement, and it may contain the keywords await, async
for, and async with.
24. CPython
CPython is the canonical implementation of Python in C. It is the one distributed on
python.org.
25. Python Decorator
https://data-flair.training/blogs/python-glossary/ 4/8
3/26/2019 59 Python Glossary of Terms You Must Know - DataFlair
A decorator is a function that returns another function, or wraps it. It adds functionality to
it without modifying it. For a simple, detailed view on decorators, refer to Python
Decorators.
26. Descriptor
If an object defines methods __get__(), __set__(), or __delete__(), we can call it a
descriptor. On looking up an attribute from a class, the descriptor attribute’s special
binding behavior activates. Using a.b looks up the object ‘b’ in the class dictionary for ‘a’. If
‘b’ is a descriptor, then the respective descriptor methods is called.
27. Python Dictionary
A dictionary is an associative array that holds key-value pairs. Think of a real-life
dictionary. Any object with __hash__() and __eq__() methods can be a key.
28. Dictionary View
A dictionary view is an object returned from dict.keys(), dict.values(), or dict.items(). This
gives us a dynamic view on the dictionary’s entries. So, when the dictionary changes, the
view reflects those changes.
29. Docstring
A docstring is a string literal that we use to explain the functionality of a class, function, or
module. It is the first statement in any of these constructs, and while the interpreter
ignores them, it retains them at runtime. We can access it using the __doc__ attribute of
such an object. You can find out more about docstrings inPython Comments.
30. Duck-Typing
We keep saying that Python follows duck-typing. But what does this mean? This means
that Python does not look at an object’s type to determine if it has the right interface. It
simply calls or uses the method or attribute. “If it looks and quacks like a duck, it must be a
duck.”
This improves flexibility by allowing polymorphic substitution. With duck-typing, you
don’t need tests like type() or isinstance(); instead, you use hasattr() tests or EAFP
programming.
31. EAFP Programming
EAFP stands for Easier to Ask for Forgiveness than Permission.
This means that Python assumes the existence of valid keys or attributes, and catches
exceptions on falsity of the assumption. When we have too many try and except statements
in our code, we can observe this nature of Python.
Other languages like C follow LBYL (Look Before You Leap).
32. Python Expression
An expression is a piece of code that we can evaluate to a value. It is an aggregation of
expression elements like literals, names, attribute access, operators, or function calls. All of
these return a value. An if-statement is not an expression, and neither is an assignment,
because these do not return a value.
33. Extension Module
An extension module is one written in C or C++, using Python’s C API to interact with the
core, and with user code.
34. f-string
An f-string is a formatted string literal. To write these, we precede a string with the letter ‘f’
or ‘F’. This lets us put in values into a string.
https://data-flair.training/blogs/python-glossary/ 5/8
3/26/2019 59 Python Glossary of Terms You Must Know - DataFlair
1. >>> name,surname='Ayushi','Sharma'
2. >>> print(f"I am {name}, and I am a {surname}")
1. >>> 18//4
-5
These are some of the terminologies from our Python Glossary. We have Python Glossary
Part II as well for more Python Glossaries. Link is Provided at the end of this article.
39. Python Function
A function is a sequence of statements that may return a value to the caller. It may take
zero or more arguments. For more on functions, read up Functions in Python.
40. Function Annotation
An annotation to a function is an arbitrary metadata value associated with a parameter or
return value. We can access a function’s annotations using the __annotations__ attribute.
And while Python itself does not assign a meaning to an annotation, third-party libraries or
tools make use of them.
41. __future__
Interestingly, in Python, we have a pseudo-module available that lets us enable new
language features that aren’t yet compatible with the current interpreter.
https://data-flair.training/blogs/python-glossary/ 6/8
3/26/2019 59 Python Glossary of Terms You Must Know - DataFlair
1. >>> __future__.absolute_import
52. Importing
Importing is the process through which we make the Python code in one module available
to another.
53. Importer
The importer is an object that finds and loads a module. Hence, it is both- a finder and a
loader object.
54. Interactive
Being of an interpreted nature, Python lets you enter statements/expressions at the integer
prompt, and immediately execute them and see results.
55. Interpreted
We couldn’t highlight this more when we say Python is an interpreted language. However,
because it does have a bytecode compiler, the distinction is a bit blurry. The source files
can run without explicitly creating an executable. While this makes Python faster to
develop/debug, it often results in slower execution.
56. Interpreter Shutdown
When we shut down the interpreter, it gradually releases all allocated resources. These
include modules and different critical internal structures. Alongside, it makes several calls
to the garbage collector. This may trigger execution of code in user-defined destructors or
in weakref callbacks. Since the resources it relies on may not function anymore during the
shutdown phase, the code executed can encounter various exceptions.
57. Python Iterable
Any object that can return its members one at a time is an iterable. Examples include lists,
strings, tuples, dicts, and file objects.
For more on iterables, read up on Python Iterables.
58. Python Iterator
An iterator is an object that represents a stream of data. We can define an iterator using the
iter() function/method, and get one object at a time with the next() function/method.
For a detailed introduction to iterators, refer to Python Iterators.
59. Key Function
It is a callable that returns a value that we can use for sorting or ordering. We also call it a
collation function. Functions like max(), min(), and sorted() make use of them.
60. Keyword Argument
Refer to section 6 for this.
This is all about the Python Glossary Part I. For more More Python Glossary see Python
Glossary Part II.
61. Conclusion: Python Glossary
Here, we discussed 59 common Python Glossary of terms we see in Python. Stay tuned for
more, and feel free to ask a doubt. If you have any query regarding Python Glossary
Tutorial, Please Comment. We hope you like the Python Glossary Tutorial.
https://data-flair.training/blogs/python-glossary/ 8/8