50 Python Glossary of Terms to Understand Python – II
Free Python course with 25 real-time projects Start Now!!
Welcome to the Part II of the Python Glossary tutorial.
We have already discussed 59 Python Glossary of terms in last article and today we will discuss some more Python terminologies.
A lambda is an anonymous inline function made of a single expression. When we call the function, it evaluates the expression and returns it.
Look Before You Leap is a coding style that explicitly tests for pre-conditions before making calls or lookups.
If your code has too many if-statements, you know it follows LBYL.
A list is a sequence of objects. This sequence is mutable, and can be heterogeneous.
4. List Comprehension
A list comprehension is a compact way to create a list.
>>> a=[i**2 for i in range(7)] >>> a
A loader is an object that loads a module. A loader object must define the method load_module(), and a finder returns a loader.
A container object, Mapping supports arbitrary key lookups.It also implements the methods specified in the MutableMapping or Mapping abstract base classes.
Examples- dict, collections.defaultdict, collections.OrderedDict and collections.Counter.
7. Meta Path Finder
The meta path finder is a finder that a search of sys.meta_path returns. It is different from a path entry finder.
Meta means beyond. This way, a metaclass is a class of a class.A regular class definition creates a name, a dictionary for it, and a list of its base classes.
The metaclass is the one that takes these three arguments, and actually creates the class.
While most object-oriented languages implement it by default, Python lets us create our own metaclasses.
Although we don’t always need this, this can provide for elegant solutions in logging attribute access, adding thread-safety, tracking object creation, implementing singletons, and other tasks.
A method is simply a function we define inside a class body.
We provide ‘self’ as the first parameter to each method; it is how it understands that it must work with this object.
10. Method Resolution Order
MRO is the order in which the interpreter searches base classes when we look a member up.
A module is any object that is an organizational unit of Python code.
While we can import modules provided by the Python, we can also create our own.
12. Module Spec
A namespace that contains the import-related information when we load a module is module spec.
It is an instance of importlib.machinery.ModuleSpec. There is a lot more terms in this Python Glossary of terms tutorial.
Read section 70 for this.
Unlike immutables, a mutable can change its value. However, it keeps its id(). Examples include lists and dictionaries.
A namedtuple lets us access a value using a label instead of an index.
We import the namedtuple() function from the module collections.
Implemented as dictionaries, namespaces hold variables. We have local, global, and nested namespaces in objects.
They prevent name collisions and provide modularity.
17. Namespace Package
It is a PEP 420 package that contains subpackages. In fact, that is all it does.
It has no physical representation, not even a __init__.py file.
18. Nested Scope
In Python, we can refer to a variable in an enclosing definition. An inner function can refer to variables in the outer function.
But when we say refer, we mean it can access that variable to read it, but cannot modify it.
An object is an instance of a class. It has attributes(state) and methods(behavior).
It is the ultimate base class of any class in Python.
A package is a container for modules and other subpackages.
Each package is like a directory, except for the fact that it has a __init__.py file. We usually keep that empty.
When we define a function or a method, we name entities that specify arguments that the function can accept when we call it.
22. Path Entry
A path entry is a single location on the import path. The path-based finder consults it to find modules to import.
23. Path Entry Finder
The path entry finder is a finder that a callable returns on sys.path_hooks.
It knows how to locate modules if it knows a path entry.
24. Path Entry Hook
It is a callable on the sys.path_hook list. If it knows how to find modules on a specific path entry, it returns a path entry finder.
25. Path Based Finder
This is a default meta path finder, and it searches for an import path for modules.
26. Path-Like Object
A path-like object is an object that represents a system file path.
It can either be a str or bytes object that represents a path, or an object that implements the os.PathLike protocol.
A portion is a set of files, in a single directory, that contribute to a namespace package.
28. Positional Argument
See section 6d in Part I.
29. Provisional API
An API purposely excluded from the standard library’s backwards-compatibility guarantees is a provisional API.
30. Python 3000
Python 3000 is a nickname for the Python 3.x release line. We also call it Py3k.
A common Python idiom is to iterate over a list using a for-loop directly instead of using a counter.
Programmers in another language would do this:
>>> nums=[1,2,3,4,5,6,7] >>> for i in range(len(nums)): print(nums[i])
A Pythonic approach to this would be:
>>> for num in nums: print(num)
So, any idea or piece of code that follows idioms of Python are Pythonic.
32. Qualified Name
A dotted name that shows us the path from a module’s global scope to a class, method, or function defined in that module.
The attribute __qualname__ will tell us.
>>> class A: class B: class C: def sayhi(self): pass >>> A.__qualname__
33. Reference Count
This is the number of references to an object. A deallocated object’s reference count drops to 0.
The function getrefcount() from the module to find out.
>>> from sys import getrefcount >>> a=7 >>> getrefcount(a)
>>> a=8 >>> getrefcount(a)
>>> a=9 >>> getrefcount(a)
34. Regular Package
A regular package is a traditional package- a directory with a __init__.py file.
__slots__ is a declaration inside a class, that pre-declares space for instance attributes, and eliminates instance dictionaries.
This way, it saves memory.
A sequence is an iterable which accesses elements efficiently with integer indices. It also has the methods __getitem__() and __len__().
Examples of sequences include lists, strings, tuples, and bytes.
37. Single Dispatch
It is a kind of a generic function dispatch where a single argument’s type decides the implementation.
A slice is an object that holds a part of a collection. For this, we use the slicing operator .
39. Special Method
A special method is one that Python calls implicitly to execute an operation on a type, say, addition.
Such a method has two leading and two trailing underscores.
Few more Python Glossary of terms and you will be aware of every Python terminology used.
A statement is a block of code. Actually, it can be an expression or a keyword.
41. Struct Sequence
A struct sequence is a tuple with named elements. So, they are like namedtuples, but lack methods like _make() and _asdict().
42. Text Encoding
We use codecs to encode Unicode strings to bytes.
43. Text File
A text file is one that can read and write str objects. To open a file in text mode, we may use ‘r’ or ‘w’ modes.
44. Triple-Quoted String
A triple-quoted string is delimited by three sets of single/double quotes.
We can use it to easily work with single/double quotes without trouble, or to create a docstring.
The type function, when we call it on an object, tells us what type of a Python object it is.
46. Universal Newlines
This is a way to interpret text streams where the following end a line:
47. Variable Annotation
A variable annotation is a type metadata value. It is associated with a class attribute or a module global variable.
Third-party libraries make use of them.
48. Virtual Environment
A virtual environment is a cooperatively isolated runtime environment.
It allows users and applications to exclusively install and upgrade Python distribution packages.
49. Virtual Machine
A VM is a computer that is entirely defined in software. The virtual machine for Python executes the bytecode that the bytecode compiler emits.
50. Zen of Python
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!
This lists out the design principles and philosophies of the language.
This is all for Python Glossary of terms.
Python Interview Questions on Glossary
- What are the basics of Python?
- What are the reserved words in Python?
- What are the basic commands in Python?
- What is variable annotation in Python?
- What is Path entry in Python?
In today’s tutorial on Python Glossary of terms we learned 50 Python terminologies that will help you when you learn and work on Python.