INTRODUCTION TO PYTHON
Programming Language Basics: It defines a programming language as an ordered set of instructions executed by a computer to perform a specific task. It distinguishes between high-level languages like Python and low-level/machine languages composed of 0s and 1s.
Python Overview:
Features of Python:
High-level language:
Python is a high-level language, offering abstractions that make it closer to human language.
Interpreted language:
Python programs are executed by an interpreter, which reads and executes the code line by line.
Ease of understanding:
Python programs are easy to understand due to their clearly defined syntax and relatively simple structure.
Case sensitivity:
Python is case-sensitive, treating variables and identifiers with different cases as distinct entities.
Portability and platform independence:
Python can run on various operating systems and hardware platforms without modification, enhancing its versatility.
Rich library of predefined functions:
Python comes with a vast standard library containing numerous modules and functions for various tasks.
Useful in web development:
Python is widely used in web development, with frameworks like Django and Flask facilitating the development of web applications.
Indentation for blocks and nested blocks:
Python uses indentation to define blocks of code, such as loops and conditionals, improving readability and enforcing code consistency.
Working with Python:
Python Interpreter:
Execution Modes:
Interactive Mode (a):
>>> prompt.Script Mode (b):
.py extension.prog5-1.py, type prog5-1.py.[Run] -> [Run Module] from the menu.IDENTIFIERS
Definition: Identifiers are names used to identify variables, functions, or other entities in a program.
Rules for Naming Identifiers:
_).a–z, A–Z, 0–9, or underscore (_).!, @, #, $, %, etc., cannot be used in identifiers.Examples:
marks1, marks2, marks3, and avg are preferable over single letters like a, b, c, or A, B, C.marks1, marks2, marks3, and avg can be used:| python |
avg = (marks1 + marks2 + marks3) / 3 |
area, length, and breadth are preferred over single alphabets for clarity and readability:| python |
area = length * breadth |
Following these rules and conventions enhances code readability and maintainability, making it easier for programmers to understand and work with Python code.
VARIABLES
Definition:
Assignment Statement:
variable_name = valueExample Program (5-2):
message, userNo, and price are assigned values of string, integer, and float types, respectively.Example Program (5-3):
length and breadth are assigned values of 10 and 20, respectively.length and breadth, and the result is stored in the variable area.print() function.