0% found this document useful (0 votes)
4 views6 pages

Python Definitions and Theory Concepts

Uploaded by

Nandini Bharat
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)
4 views6 pages

Python Definitions and Theory Concepts

Uploaded by

Nandini Bharat
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
You are on page 1/ 6

Python Definitions and Theory Concepts

I. Definitions of Key Terminology


Term Definition Source
s

Argument The actual value supplied to a function's parameter.


Also referred to as positional arguments or keyword
arguments.

Augmented A shorter form for writing assignment operations (e.g.,


Assignment x += 3). Can be used to increment, subtract, or
Operator multiply a number by a value.

Boolean Value (bool) A simple data value that can be either True or False.
They are similar to yes and no in English. Boolean
literals are True and False (case sensitive).

Class A blueprint or template for creating objects. Used to


define new custom types to model real-world concepts.

Code Editor A tool used to write code, similar to how Microsoft Word
is used for documents.

Comment Additional notes added to a program, indicated using a


hash sign (#). They are ignored by the Python
interpreter.

Constructor A special method (function) that gets called when


(__init__) creating an object (an instance of a class). Used to
initialize the object's attributes.

Dictionary A data structure used to store information in key-value


pairs. Defined using curly braces ({}). Keys in a
dictionary must be unique.

Docstrings Documentation using triple quotes used for modules,


classes, and functions.

Expression A piece of code that produces a value. The Python


interpreter evaluates expressions.

Floating Point A number that includes a decimal point.


Number (float)

Function A container for a few lines of code that perform a


specific task. They are reusable chunks of code.
Functions either perform a task or calculate and return
a value.

IDE (Integrated A specialized code editor with advanced features such


Development as auto-completion, debugging, and testing utilities,
Environment) simplifying the coding process.

Integer (int) A whole number without a decimal point. Integer literals


can be Decimal, Binary (0b), Octal (0o), or
Hexadecimal (0x).

Iterable Object An object that can be iterated over, or used in a for


loop (e.g., strings, lists, range objects).

Keyword Argument An argument supplied to a function by explicitly stating


the parameter's name followed by its value (e.g.,
last_name=smith). Their position does not matter.

List An ordered collection of items defined using square


brackets ([]). Lists are mutable sequences.

Linter A tool (like Pylint) that analyzes code for potential


errors (especially syntactical errors) before running the
program.

Local Variables Variables that are block-scoped and accessible only


within their scope (e.g., inside a function).

Method A function that belongs to a specific object or class.


They are accessed using the dot operator (.).

Module A separate file containing reusable Python code


(functions and classes) used to organize code.

None An object in Python that represents the absence of a


value. It is a singleton object. Functions return None by
default if no explicit return statement is present.

NotImplemented A special value indicating that a method isn't


implemented for specific operand types, allowing
Python's runtime to continue chain computation.

Object (Instance) An actual instance created from a class, based on the


class's blueprint.

Package A container for multiple related modules. In the file


system, this is a directory or folder containing an
__init__.py file.
Parameter A placeholder defined in a function signature for
receiving inputs.

PEP 8 (Python A popular style guide among Python developers that


Enhancement defines best practices and conventions for formatting
Proposal 8) and styling Python code.

Python Bytecode A portable, intermediate language that CPython


compiles Python source code into before it is executed
by the Python Virtual Machine (PVM).

Python Interpreter A program that executes Python code by translating


Python instructions into instructions a computer can
understand. It executes code line by line from the top.

Python Virtual A component that takes Python bytecode and converts


Machine (PVM) it into machine code for execution.

Sequence Ordered collections of items indexed by non-negative


integers (0, 1, 2, ...). Sequences can be mutable (lists)
or immutable (strings, tuples).

String (str) A programming term for a series of characters (text).


Defined using quotes (single, double, or triple for multi-
line). Strings are immutable sequences of Unicode
code points.

Syntax The grammar of a programming language. Bad


grammar/structure results in a Syntax Error.

Tuple A collection of items defined using parentheses (()).


Similar to a list, but tuples are immutable (cannot be
modified).

Unpacking A feature that assigns values from a sequence (like a


tuple or list) into multiple variables in a single
assignment statement.

Variable A label used to reference a memory location where


data is temporarily stored.

II. Core Concepts and Theories


A. Python Language and Environment

● Python Implementations Python refers both to the language specification (rules and
grammar) and specific implementations (programs that execute the code).
○ CPython: The default and most widely used implementation, written in C. It
compiles Python code to Python bytecode, which is run by the Python Virtual
Machine (PVM).
○ Jython: An implementation written in Java that compiles Python code into
Java bytecode, allowing the reuse of existing Java code.
○ IronPython: An implementation written in C# (or C) that allows the reuse of
C# code.
● High-Level Language Python is a high-level language, meaning developers do not
have to worry about complex tasks such as memory management, unlike languages
like C++.
● Cross-Platform Python applications can be built and run on various operating
systems including Windows, Mac, and Linux.
● Dynamically Typed Python determines the type of variables at runtime, meaning
explicit type declarations are generally not required, although type hints can be used
for clarity.
● Case Sensitivity Python is a case-sensitive language, meaning lowercase and
uppercase letters are treated differently (e.g., False and false are not the same).

B. Data Handling and Operators

● Data Types Primitive built-in types include strings, numbers (integers, floats,
complex numbers), and booleans. Complex types include lists, dictionaries, tuples,
and range objects.
● Constants Constants are conventionally named using all-caps (Pascal naming
convention) and can be annotated with Final to indicate they should not be
reassigned.
● Variable Naming Conventions Variables should have descriptive and meaningful
names, use lowercase letters, and separate multiple words using an underscore (_).
● Arithmetic Operators Standard mathematical operators are supported: addition (+),
subtraction (-), multiplication (*), division (/), integer division (//), modulus (%), and
exponentiation (**).
● Operator Precedence Defines the order in which operations are executed
(Exponentiation > Multiplication/Division > Addition/Subtraction). Parentheses () can
be used to override this order.
● String Indexing and Slicing Strings are indexed starting from 0 (zero-indexed).
Negative indices start from the end (-1 for the last character). Slicing [start:end]
returns characters up to, but excluding, the character at the end index.
● Type Coercion Unlike some other languages (e.g., JavaScript), Python does not
perform type coercion during comparison. If types do not match, comparison returns
False.

C. Control Flow and Loops

● Conditional Statements Decisions are made using if statements, often followed by


elif (else if) and optionally terminated with else.
● Indentation and Blocks Code blocks (e.g., under if or for) are defined by
consistent indentation, typically four white spaces, as recommended by PEP 8.
● Logical Operators and, or, and not are used to combine or modify boolean
expressions. They are short-circuit operators, meaning evaluation stops as soon as
the result is determined.
● Ternary Operator A shorthand way to assign a value based on a condition: x if
condition else y.
● for Loop Used to iterate over items in an iterable object (collection). The for-else
statement allows the else block to execute only if the loop finishes without a break.
● while Loop Executes a block of code repeatedly as long as a given condition
remains True. Requires a method (like break or condition change) to prevent an
infinite loop.
● Loop Control Statements
○ break: Immediately exits the loop.
○ continue: Skips the remaining code in the current iteration and moves to
the next iteration.
○ pass: A null operation used as a placeholder where syntax requires a
statement but no action is desired (e.g., in an empty class definition).

D. Functions and Object-Oriented Programming (OOP)

● Function Definition Functions are defined using the def keyword, followed by the
function name, parameters in parentheses, and a colon.
● Function Return The return statement is used to send a value back to the caller.
By default, functions return the None value.
● Keyword Arguments Primarily used to increase code readability, especially when
dealing with functions that take multiple numerical arguments. Keyword arguments
must follow positional arguments if both are used.
● Optional Parameters Parameters can be made optional by assigning them a default
value in the function definition. Optional parameters must follow all required
parameters.
● Classes and Object Instantiation Classes serve as blueprints. Objects are
instances of classes.
● self Reference In class methods, self is automatically passed as the first
parameter, providing a reference to the current object instance.
● Inheritance A core OOP mechanism for code reuse, where a child class inherits
methods and attributes from a parent class.
● DRY Principle Stands for "Don't Repeat Yourself"; a best practice in programming to
avoid duplicating code.

E. Error Handling and Modules

● Try/Except Used to gracefully handle exceptions (errors that crash a program). Code
that might fail is placed in the try block, and error-handling logic is placed in the
except block, specified by the error type (e.g., ValueError).
● Exit Codes An exit code of 0 indicates the program terminated successfully. Any
non-zero exit code (e.g., 1) indicates a crash or failure.
● PyPI (Python Package Index) A large directory of external packages and libraries
built by the Python community for reuse.
● pip The standard tool used to install and uninstall packages registered on PyPI.

F. Machine Learning (AI Subset)

● Machine Learning (ML) A subset of AI used to solve complex problems by building


a model and feeding it vast amounts of data so it can find and learn patterns for
prediction.
● ML Project Steps
1. Import Data: Often from a CSV file.
2. Clean/Prepare Data: Involves tasks like removing duplicates, handling
null/incomplete values, removing irrelevant data, and converting text-based
data to numerical values.
3. Split Data: Separate the dataset into an input set (features/profile data) and
an output set (predictions/answers).
4. Create Model: Select an algorithm (e.g., decision trees, neural networks).
5. Train Model: Feed the model the training data (e.g., 70-80% of the dataset).
6. Make Predictions: Ask the trained model for an output based on new input.
7. Evaluate Accuracy: Compare predictions against known test values (e.g.,
20-30% of the dataset).
● Model Persistence The practice of saving a trained model to a file after training so it
can be loaded later to make predictions without requiring retraining, which can be
time-consuming.
● Decision Tree A simple machine learning algorithm (classifier) that visualizes
predictions using a binary tree structure, where nodes contain conditions leading to
classifications (classes).
● ML Libraries Popular Python libraries for ML include Numpy (multidimensional
arrays), Pandas (data analysis/data frames), Matplotlib (plotting), and Scikit-learn
(sklearn) (common ML algorithms).
● Data Frame A two-dimensional data structure, similar to an Excel spreadsheet,
provided by the Pandas library.

You might also like