Python is a high-level, interpreted programming language. Before diving into Python, it is essential to understand the fundamental concepts of programming languages and how they bridge the gap between human logic and machine execution.
To write and run Python programs, we use a Python interpreter (also called the
Python shell
), indicated by the prompt
>>>
.
>>> 1 + 2
3
>>> "Hello " + "World"
'HelloWorld'
.py
extension, and executing it as a whole.
# Save as prog5-1.py
print("Save Earth")
print("Preserve Future")
Keywords are reserved words with specific meanings for the interpreter. They must be written exactly as defined (case-sensitive).
| Keyword | Keyword | Keyword | Keyword | Keyword |
|---|---|---|---|---|
| False | class | finally | is | return |
| None | continue | for | lambda | try |
| True | def | from | nonlocal | while |
| and | del | global | not | with |
| as | elif | if | or | yield |
| assert | else | import | pass | |
| break | except | in | raise |
Identifiers are user-defined names used to identify variables, functions, or other entities in a program.
_
).
a-z, A-Z, 0-9, _
).
!, @, #, $, %, etc.
A variable is a named reference to an object stored in memory. In Python, variable declaration is implicit (created automatically upon first assignment).
gender = 'M'
message = "Keep Smiling"
price = 987.9
Comments are non-executable notes added to source code to improve readability. In Python, comments begin with a hash sign (
#
).
# This is a single-line comment
amount = 3400 # Inline comment
Python treats every value or data item as an object. Each object is assigned a unique identity (ID) representing its memory address, which can be retrieved using the id() function.
Data types identify the type of values a variable can hold and the operations that can be performed on them.
| Core Computer Science Concept | Technical Definition / Operational State | Structural Parameters & Specifications | Computational Function & System Purpose |
|---|---|---|---|
| Numbers | Stores numerical values. | Classified into int , float , and complex . Includes bool as a subtype of integer. | Performs mathematical computations. |
| Sequence | An ordered collection of items indexed by integers. | Includes String (immutable), List (mutable), and Tuple (immutable). | Manages ordered datasets. |
| Sets | An unordered collection of unique items. |
Enclosed in curly brackets
{ }
. Mutable but cannot contain duplicate elements.
|
Performs mathematical set operations and eliminates duplicates. |
| None | A special data type representing the absence of a value. |
Has only one value:
None
. Supports no special operations.
|
Acts as a placeholder or default return value. |
| Mapping | An unordered collection of key-value pairs. |
Represented by
Dictionary
(enclosed in
{ }
with
key:value
syntax).
|
Provides fast, key-based lookups. |
+
(Addition/Concatenation),
-
(Subtraction),
*
(Multiplication/Replication),
/
(Division),
%
(Modulus),
//
(Floor Division),
**
(Exponentiation).
==
,
!=
,
>
,
<
,
>=
,
<=
. Evaluate to
True
or
False
.
=
,
+=
,
-=
,
*=
,
/=
,
%=
,
//=
,
**=
.
and
,
or
,
not
.
is
,
is not
(checks if two variables point to the same memory location).
in
,
not in
(checks if a value exists within a sequence).
When an expression contains multiple operators, precedence determines the evaluation order (from highest to lowest):
**
(Exponentiation)
~, +, -
(Complement, unary plus, unary minus)
*, /, %, //
(Multiply, divide, modulo, floor division)
+, -
(Addition, subtraction)
<=, <, >, >=, ==, !=
(Relational/Comparison)
=, %=, /=, //=, -=, +=, *=, **=
(Assignment)
is, is not
(Identity)
in, not in
(Membership)
not
,
and
,
or
(Logical)
Technical Profile: Built-in I/O Functions
sep
defines the separator between values, and
end
defines the character appended at the end of the output.
int()
,
float()
,
str()
,
chr()
, and
ord()
.
# Explicitly converting string input to integer
age = int(input("Enter your age: "))
num1 = 10 # int
num2 = 20.0 # float
sum1 = num1 + num2 # Result is 30.0 (float)
Debugging is the process of identifying and removing bugs (errors) from a program.
10 + 12/2
instead of
(10 + 12)/2
).
Case Study: Student Management Information System (SMIS)
Socio-Technical Analysis & Core Systemic Impact: Implementing an automated SMIS requires robust input validation and explicit type casting to prevent runtime crashes. For instance, capturing numeric fields like "Roll No" or "Phone Number" requires converting raw string inputs from
input()into integers usingint(), while ensuring proper exception handling is in place to catch non-numeric inputs that trigger runtimeValueErrorexceptions. Proper documentation and consistent naming conventions (e.g.,first_numorfirstNum) are critical for collaborative software maintenance.