0% found this document useful (0 votes)
1 views4 pages

Core Python Syntax

Summary: Concise glossary of core Python terms and concepts. Origin: Likely compiled from teaching notes or a study guide. useful for beginners building vocabulary and understanding Python fundamentals. Defines interpreter, variables, mutable/immutable, functions, OOP (class/self), generators, decorators, and GIL.

Uploaded by

isbrice6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views4 pages

Core Python Syntax

Summary: Concise glossary of core Python terms and concepts. Origin: Likely compiled from teaching notes or a study guide. useful for beginners building vocabulary and understanding Python fundamentals. Defines interpreter, variables, mutable/immutable, functions, OOP (class/self), generators, decorators, and GIL.

Uploaded by

isbrice6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

CORE PYTHON SYNTAX &

CONCEPTS
 Interpreter: The program that reads and executes Python code directly, line by line. Unlike
compiled languages (e.g., C++), Python code doesn't need to be compiled into a separate
executable before running.
 Script: A file containing Python code (usually with a .py extension) that is intended to be
executed directly.
 Variable: A symbolic name that is a reference or pointer to an object. You assign a value to a
variable using the = operator (e.g., x = 5).
 Statement: A single unit of code that the Python interpreter can execute (e.g., an assignment
statement, an if statement, a for loop).
 Expression: A combination of values, variables, operators, and calls to functions that
evaluates to a single value (e.g., 2 + 3, x * y, func()).
 Indentation: The use of whitespace (spaces or tabs) at the beginning of a line to define blocks
of code. In Python, indentation is syntactically significant and defines code structure (like
curly braces {} in other languages).
 Comment: Text in the code that is ignored by the interpreter. It starts with a # and is used to
explain code for human readers.
 Keyword (Reserved Word): A word that has a special meaning in Python and cannot be used
as a variable name, function name, or any other identifier (e.g., if, for, while, def, class,
import).

Data Types & Structures


 Object: The fundamental concept in Python. Everything in Python is an object (e.g., integers,
strings, functions, classes). Objects have an identity (memory address), a type, and a value.
 Type: The category of data an object belongs to (e.g., int, str, list). It defines the operations
that can be performed on the object. You can check it with type().
 Mutable Object: An object whose internal state (value) can be changed after it is created
(e.g., list, dict, set).
 Immutable Object: An object whose internal state (value) cannot be changed after it is
created (e.g., int, float, str, tuple).
 Sequence: An iterable container that supports efficient element access using integer indices
(e.g., list, tuple, str).
 List: A mutable, ordered collection of items. Defined with square brackets [].
 Tuple: An immutable, ordered collection of items. Defined with parentheses (). Often used
for heterogeneous data.
 Dictionary (dict): A mutable, unordered collection of key-value pairs. Keys must be
immutable. Defined with curly braces {}.
 Set: A mutable, unordered collection of unique, immutable objects. Defined with curly
braces {} (but without key-value pairs).
 String (str): An immutable sequence of Unicode characters. Defined with single, double, or
triple quotes ('hello', "world", """multiline""").
 Boolean (bool): A data type that can only have one of two values: True or False.

Functions
 Function: A block of reusable code that performs a specific task. Defined using the def
keyword.
 Parameter: A variable listed inside the parentheses in the function definition. It's a
placeholder for the value that will be passed to the function.
 Argument: The actual value that is passed to the function when it is called.
 Return Statement (return): The statement used to exit a function and pass a value back to the
caller.
 Lambda Function: A small, anonymous (unnamed) function defined using the lambda
keyword. It can have any number of arguments but only one expression (e.g., lambda x: x*2).
 Scope (LEGB Rule): The region of a program where a variable is accessible. The search
order is: Local -> Enclosing -> Global -> Built-in.
 *args: A special syntax in a function parameter to pass a variable number of non-keyword
arguments. The function receives them as a tuple.
 **kwargs: A special syntax in a function parameter to pass a variable number of keyword
arguments. The function receives them as a dictionary.

Object-Oriented Programming (OOP)


 Class: A blueprint for creating objects. It defines the attributes (data) and methods (functions)
that the objects created from it will have.
 Instance: An individual object created from a class. If Dog is a class, then my_dog = Dog()
creates an instance of the Dog class.
 Method: A function that is defined inside a class and is associated with the objects created
from that class.
 self: The first parameter of an instance method. It is a reference to the current instance of the
class and is used to access variables and methods associated with that instance.
 Constructor (__init__): A special method that is automatically called when a new instance of
a class is created. It's used to initialize the object's attributes.
 Inheritance: A mechanism where a new class (child class) is derived from an existing class
(parent class). The child class inherits attributes and methods from the parent.
 Encapsulation: The bundling of data (attributes) and methods that operate on that data into a
single unit (a class). It often involves restricting direct access to some of an object's
components (using "private" attributes, conventionally with a leading underscore _).
 Polymorphism: The ability to present the same interface for different underlying data types.
For example, the + operator can be used for addition (numbers) or concatenation (strings).

Control Flow & Iteration


 Conditional Statement (if, elif, else): Statements that run different blocks of code based on
whether a condition is True or False.
 Loop (for, while): A control structure that repeats a block of code multiple times.
 Iterable: Any Python object capable of returning its elements one at a time. It can be looped
over (e.g., list, str, dict, file).
 Iterator: An object that represents a stream of data. It returns data one element at a time when
next() is called on it. All iterators are iterables, but not all iterables are iterators.
 Generator: A special kind of iterator that generates values on-the-fly using the yield keyword
instead of storing them all in memory at once. They are memory efficient.
 yield: A keyword used in a function like a return statement, but it returns a generator object.
The function's state is paused and saved, to be resumed on the next call.
 Modules & Packages
 Module: A single Python file (with a .py extension) containing Python code, such as
functions, classes, and variables. You can import it using the import statement.
 Package: A collection of modules in a directory that includes a special __init__.py file. It's a
way of structuring Python's module namespace.
 PIP (Package Installer for Python): The standard package manager for Python. It is used to
install and manage software packages written in Python from the Python Package Index
(PyPI).

Advanced Concepts
 List Comprehension: A concise way to create lists. It consists of brackets containing an
expression followed by a for clause (e.g., [x**2 for x in range(10)]).
 Dictionary Comprehension: A concise way to create dictionaries (e.g., {x: x**2 for x in
range(5)}).
 Exception: An error that occurs during program execution. When an error occurs, an
exception object is created and "raised".
 try / except: A block of code used to catch and handle exceptions, preventing the program
from crashing.
 Dunder Methods (Magic Methods): Special methods with double underscores at the
beginning and end (e.g., __init__, __str__, __len__). They are called automatically by Python
in specific situations.
 Decorator: A powerful tool that allows you to modify or extend the behavior of a function or
method without permanently changing its source code. It is a function that takes another
function as an argument.
 Context Manager: An object that defines the runtime context to be established when using
the with statement. It is used for resource management (e.g., automatically closing a file). It
uses the __enter__ and __exit__ dunder methods.
 GIL (Global Interpreter Lock): A mutex (lock) in the CPython interpreter that allows only
one thread to execute Python bytecode at a time. This simplifies memory management but
can be a bottleneck for CPU-bound multi-threaded programs.
 This list covers the most common and important terms you'll encounter while learning and
working with Python.

You might also like