Python Glossary

The Python Glossary provides definitions of terms, concepts, and commonly used terminology in Python programming. Here’s a list of important Python glossary terms and their meanings:

A

  • Argument: A value passed to a function (or method) when calling it. Arguments can be positional or keyword arguments.
  • Attribute: A value or method that is associated with an object. For example, my_obj.attribute accesses an attribute of my_obj.

B

  • Bytecode: Python source code is compiled into a set of instructions (bytecode) that can be executed by the Python interpreter.

C

  • Class: A blueprint for creating objects (instances). Classes encapsulate data for the object and methods to manipulate that data.
  • Constructor: The __init__() method of a class that initializes new objects.
  • Comprehension: A compact way to process sequences and return modified sequences. Examples include list comprehensions and dictionary comprehensions.
    squares = [x**2 for x in range(5)]
    
  • Closure: A function object that remembers values in enclosing scopes even if they are not present in memory.
  • Coroutine: A function that can pause its execution and yield control back to the caller using the yield or await keyword, and later resume from where it left off.

D

  • Decorator: A function that takes another function and extends or modifies its behavior. Commonly used to modify the behavior of functions or methods.
    @decorator_function
    def my_function():
        pass
    
  • Dictionary: A built-in data type that stores key-value pairs. Dictionaries are unordered, mutable, and indexed by keys.
    my_dict = {"name": "Alice", "age": 25}
    

E

  • Exception: An error that occurs during the execution of a program. Exceptions can be handled using try and except blocks.
    try:
        x = 10 / 0
    except ZeroDivisionError:
        print("Cannot divide by zero")
    

F

  • Function: A block of reusable code that performs a specific task. It is defined using the def keyword.
    def my_function():
        pass
    

G

  • Generator: A function that returns an iterator that yields values one at a time. Generators are created using the yield statement.
    def my_generator():
        yield 1
        yield 2
    
  • Global Variable: A variable that is defined outside any function or class and can be accessed from any part of the code.

H

  • Hashable: An object is hashable if it has a hash value that does not change during its lifetime. Immutable types like strings, numbers, and tuples are hashable.

I

  • Immutable: An object whose value cannot be changed after it is created. Strings, numbers, and tuples are examples of immutable objects.
  • Iterable: An object that can return its elements one at a time. Examples include lists, tuples, dictionaries, and strings.
  • Iterator: An object representing a stream of data. Iterators implement the __iter__() and __next__() methods.
    my_list = [1, 2, 3]
    iterator = iter(my_list)
    print(next(iterator))  # Output: 1
    

J

  • JSON (JavaScript Object Notation): A lightweight data interchange format that is easy for humans to read and write and easy for machines to parse and generate. Python provides the json module to work with JSON data.
    import json
    json_data = json.dumps({"name": "Alice", "age": 25})
    

K

  • Keyword Argument: A named argument passed to a function. It is specified by the argument’s name and value in the function call.
    def greet(name="John"):
        print(f"Hello, {name}!")
    
    greet(name="Alice")
    

L

  • Lambda: A small anonymous function defined using the lambda keyword. Lambda functions are limited to a single expression.
    add = lambda x, y: x + y
    
  • List: A built-in data type that represents a mutable, ordered sequence of elements.
    my_list = [1, 2, 3, 4]
    

M

  • Module: A file containing Python code (functions, classes, or variables) that can be imported and used in other scripts or modules.
    import math
    print(math.sqrt(16))  # Output: 4.0
    
  • Mutable: An object that can be changed after it is created. Lists, dictionaries, and sets are mutable objects.

N

  • Namespace: A container that holds a set of identifiers (names) and their corresponding objects. The Python interpreter uses namespaces to keep track of all the variables and objects in a program.

O

  • Object: Everything in Python is an object. An object is an instance of a class, containing both data (attributes) and functionality (methods).
  • Operator: A symbol used to perform operations on variables and values. Common operators include +, -, *, /, ==, and !=.

P

  • PEP (Python Enhancement Proposal): A design document providing information or proposing new features to the Python community. PEP 8, for example, is the style guide for Python code.
  • Polymorphism: The ability of different object types to respond to the same method call in a way specific to their type.
    class Animal:
        def sound(self):
            pass
    
    class Dog(Animal):
        def sound(self):
            return "Bark"
    
    class Cat(Animal):
        def sound(self):
            return "Meow"
    

Q

  • Queue: A data structure that stores elements in a first-in-first-out (FIFO) order. Python’s queue module provides thread-safe queues.
    import queue
    q = queue.Queue()
    

R

  • Recursion: A function that calls itself during its execution. Recursive functions are useful for solving problems that can be broken down into smaller, similar problems.
    def factorial(n):
        if n == 0:
            return 1
        else:
            return n * factorial(n - 1)
    

S

  • Set: A built-in data type representing an unordered collection of unique elements.
    my_set = {1, 2, 3}
    
  • Slice: A portion of a sequence. In Python, slices can be created using the slicing syntax (start:stop:step).
    my_list = [1, 2, 3, 4]
    sliced = my_list[1:3]  # Output: [2, 3]
    
  • String: A sequence of characters. Strings are immutable and enclosed in single, double, or triple quotes.
    my_string = "Hello, World!"
    

T

  • Tuple: An immutable, ordered sequence of elements.
    my_tuple = (1, 2, 3)
    
  • Type: The kind of object an entity is. Python provides a built-in function type() to determine the type of an object.
    print(type(123))  # Output: <class 'int'>
    

U

  • Unicode: A character encoding standard that represents characters from all languages. Python 3 uses Unicode for strings by default.

V

  • Variable: A name that refers to a value stored in memory. Variables in Python are created when they are first assigned a value.
    x = 10
    

W

  • Whitespace: Any space, tab, or newline character. Python uses indentation (whitespace) to define the structure of the code (e.g., blocks of code in loops and functions).

X

  • XML (Extensible Markup Language): A markup language used to define and structure data. Python provides the xml module to work with XML data.

Y

  • Yield: A keyword used in generator functions. It pauses the function, saves its state, and returns a value to the caller, resuming where it left off when called again.
    def my_gen():
        yield 1
        yield 2
    

Z

  • Zen of Python: A collection of guiding principles for writing computer programs in Python, available by importing this.
    import this
    

This glossary covers essential Python terms, concepts, and keywords that are commonly used in the language. Understanding these terms helps when writing, reading, and discussing Python code.

Leave a Reply 0

Your email address will not be published. Required fields are marked *