ЁЯФм
ЁЯзм
ЁЯФн
ЁЯкР
ЁЯзк
тЖР Back to Dashboard
Font Size:

1. Introduction

Python is a high-level, general-purpose, interpreted programming language created by Guido van Rossum in the Netherlands. Its first version, Python 0.9.0, was released in 1991, and the name was inspired by the British comedy show "Monty Python's Flying Circus", not by the snake. Python was designed with an emphasis on code readability; its syntax is clean, simple and closely resembles the English language, which makes it an ideal first language for beginners and a powerful tool for professionals.

Python is an interpreted language, meaning that an interpreter translates and executes the source code line by line at runtime, rather than compiling the entire program to machine code in advance. Python is also dynamically typed; the programmer does not declare the data type of a variable, and the type is determined at runtime from the value assigned. These features make Python extremely flexible and easy to debug, though generally slower than compiled languages like C. Python is free and open source, and it runs on almost every platform, including Windows, Linux and macOS.

Today Python is one of the most popular programming languages in the world. It is used for web development, data science, artificial intelligence, scientific computing, automation, game development and, of course, as the primary teaching language in Indian schools. This chapter introduces the student to the Python environment: how Python is organised, how to run programs, and the very first elements of the language, such as comments and the print function.

2. Features of Python

Python owes its popularity to a combination of excellent features:

3. Python Software and Installation

Python software is distributed in the form of an interpreter package that includes the core interpreter and a standard library of modules. The official distribution can be downloaded from the Python Software Foundation website. On most GNU/Linux and macOS systems, Python comes pre-installed, but an updated version can be installed easily.

The most popular way to interact with Python for beginners is IDLE (Integrated Development and Learning Environment), which is bundled with the standard Python installation. IDLE provides an interactive shell, an editor window with syntax highlighting, and a debugger. Two common working modes exist in IDLE:

4. Running Python Programs

A Python program, called a script, is stored in a file with the .py extension. To execute it, the script file is given to the Python interpreter. There are several ways to run Python code:

# This is my first Python program saved as first.py
print("Hello, World!")
print("Welcome to Computer Science Class 11")

When this script runs, the interpreter reads the file line by line, converts the statements into an intermediate form called bytecode, and executes them, producing the output shown on the screen. Python first converts source to bytecode, then the Python Virtual Machine executes it.

5. Comments

Comments are lines in the source code that are ignored by the interpreter. They exist to help human readers understand the program. Python supports two forms of comments:

# This is a single-line comment
print("Comment is ignored above")

'''
This is a multi-line string used as a docstring.
It can span several lines.
'''
print("Documentation done")

Comments do not affect the output of a program; they are purely for human readability. Good programmers use comments to explain the why, not the what, of their code.

6. The print() Function

The print() function is the standard way to display output in Python. It writes its arguments to the console. It can accept one or more values, separated by commas, and joins them with a space by default.

print("Hello")
print(42)
print("Result is", 42)
print("Class", 11, "Computer Science")

Key facts about print():

7. Python Character Set and Tokens

A character set is the set of valid characters that can be used in a Python program. Python's character set includes: - Letters: A-Z, a-z - Digits: 0-9 - Whitespace: space, tab, newline - Special symbols: + - * / % < > = ! & | ^ ~ , . ; : ( ) [ ] { } @ # $ etc.

The smallest individual units of a program are called tokens. Python breaks the source code into five types of tokens: 1. Keywords: Reserved words with fixed meanings such as if, else, while, for, def, import, True, False, None. They cannot be used as variable names. 2. Identifiers: Names given by the programmer to variables, functions, classes, etc. 3. Literals: Data values written directly in the program, such as 42, 3.14, "Hello", True. 4. Operators: Symbols that perform operations, such as +, -, , /, ==, <. 5. Punctuators (Delimiters):* Symbols used for grouping and separation, such as ( ) [ ] { } , ; :.

8. Keywords and Identifiers

Keywords are reserved words whose meaning is fixed by the Python language. They cannot be redefined or used as identifiers. Examples include: False, True, None, and, or, not, if, elif, else, for, while, break, continue, def, return, import, from, class, in, is, lambda, try, except, finally, with, as, pass, del, global, nonlocal, raise, yield and assert.

Identifiers are the names used for variables, functions and other objects. The rules for forming a valid identifier are:

valid = 10        # valid
_valid = 20       # valid, leading underscore allowed
name_1 = "Aman"   # valid
# 2nd_name = 5    # invalid: begins with a digit
# if = 10         # invalid: 'if' is a keyword

9. Python Variable Naming Conventions

Although the language rules define what is legal, community conventions make code readable:

Quick Revision Tables

Table 1: Ways to Run Python

Mode Where Best For
Interactive IDLE shell / terminal (>>>) Experimenting, quick checks
Script IDLE editor / file with .py Real programs, multiple lines
From terminal python script.py Running saved programs

Table 2: Python Tokens

Token Examples Purpose
Keywords if, while, def, True Reserved words with fixed meaning
Identifiers num, total, avg User-defined names
Literals 42, 3.14, "Hi", True Data values
Operators +, -, *, /, == Perform operations
Punctuators ( ) , : ; [ ] Grouping and separation

Mind Map

flowchart TD A[Getting Started with Python] --> B[Creator Guido van Rossum] A --> C[Features] C --> C1[Interpreted] C --> C2[High-level] C --> C3[Dynamically typed] C --> C4[Free and open source] A --> D[Working Modes] D --> D1[Interactive IDLE] D --> D2[Script mode] A --> E[Basic Elements] E --> E1[Comments] E --> E2[print function] E --> E3[Character set] A --> F[Tokens] F --> F1[Keywords] F --> F2[Identifiers] F --> F3[Literals] F --> F4[Operators] F --> F5[Punctuators]

Important Diagrams (SVG)

Diagram 1: Python Execution Flow

How a Python Program Runs Source Code script.py Interpreter Line by line OUTPUT Bytecode Intermediate form Python Virtual Machine Executes bytecode Golden Rule: Python source is compiled to bytecode, then the Python Virtual Machine executes it line by line.

Diagram 2: Valid and Invalid Identifiers

Identifier Rules VALID student_age total marks1 Name PI Start with letter/underscore, only letters, digits, INVALID 2nd_name my name if for total@x Cannot start with a digit, no spaces/symbols, no keywords Python is case sensitive: Name, name and NAME are three different identifiers. Golden Rule: Identifiers start with a letter or underscore, contain letters/digits/underscores, and are never keywords.

Common Mistakes

  1. Forgetting to enclose strings in quotes: print(Hello) causes a NameError because Hello is treated as an identifier, not a string.
  2. Starting an identifier with a digit: Names like 1st_number cause a SyntaxError. They must start with a letter or underscore.
  3. Using a keyword as a variable name: Assignments like if = 5 produce a SyntaxError because if is reserved.
  4. Confusing interactive and script mode: Typing multi-line programs in the interactive shell produces immediate errors; write scripts in the editor and run them.
  5. Expecting print(2 + 3) to print "2 + 3": Expressions inside print are evaluated first, so it prints 5.
  6. Mixing up case sensitivity: Writing Print() instead of print() fails because Python is case sensitive and there is no built-in Print.
  7. Forgetting indentation is meaningful: In Python, indentation defines blocks; random indentation leads to IndentationError.
  8. Thinking comments affect output: A comment does nothing at runtime; the output is produced only by executable statements.

Exam Tips

  1. Know that Python was created by Guido van Rossum and is interpreted; this fact appears frequently in objective questions.
  2. Memorise the five token types (keyword, identifier, literal, operator, punctuator) and give one example of each.
  3. Learn the identifier rules precisely, especially "cannot start with a digit" and "cannot be a keyword".
  4. Remember the print() details: default separator is a space, default end is newline, and expressions are evaluated before printing.
  5. List at least five features of Python (interpreted, high-level, dynamically typed, open source, portable) for long-answer questions.
  6. Practise identifying valid vs invalid identifiers and comments in short objective questions; these are scoring marks.
  7. Understand bytecode and the Python Virtual Machine because questions about how Python executes code are common.

Conclusion

Getting started with Python means understanding not only the language but also the environment in which it runs. Python is a high-level, interpreted, dynamically typed language whose readable syntax makes it ideal for beginners. Programs are written as .py scripts and executed by the interpreter, which converts them to bytecode before running them in the Python Virtual Machine. Comments help document the code, and the print() function provides output. Every program is built from tokens: keywords, identifiers, literals, operators and punctuators, and identifiers must follow strict naming rules. With the environment and basics in place, the next chapter dives into Python fundamentals: variables, literals and operators in detail.