INTRODUCTION TO PYTHON
Summary
This chapter provides an introduction to the Python programming
language, covering its history, features, and basic operations. Created by
Guido van Rossum and released in 1991, Python is a high-level,
interpreted, and versatile language known for its simple, English-like
syntax. The document explains how to use Python in two primary modes—
Interactive for quick commands and Script for longer programs. It
further details the building blocks of Python, including tokens (keywords,
identifiers, literals), variables, and various data types like numbers and
strings.
Key Points
Features: Python is free, open-source, platform-independent, and
has an extensive library for fields like data science.
Interpreted Language: It uses an interpreter to execute code line-
by-line, converting it into bytecodes.
Case-Sensitivity: Python is case-sensitive, meaning identifiers like
age and Age are treated as different entities.
Dynamic Typing: Variables do not need explicit type declarations
and can change types during runtime.
Tokens: The smallest meaningful elements in a program, such as
keywords (reserved words like if, while) and identifiers (user-defined
names).
Core Functions: print() is used to display output, while input() is
used to accept user data as a string.
Multiple Choice Questions (MCQs)
1. Who created the Python programming language? a) James Gosling b)
Guido van Rossum c) Dennis Ritchie d) Bjarne Stroustrup Answer: b)
Guido van Rossum
2. Which mode is used for writing and saving lengthy Python programs? a)
Interactive Mode b) Immediate Mode c) Script Mode d) Command Mode
Answer: c) Script Mode
3. What is the default data type of the value returned by the input()
function? a) Integer b) Float c) String d) Boolean Answer: c) String
4. Which of the following is a valid variable name in Python? a) 2my_var b)
my-var c) _my_var d) if Answer: c) _my_var
5. Which escape sequence is used to start a new line in the print()
function? a) \t b) \s c) \n d) \r Answer: c) \n
2-Marker Questions
Q1. Define 'Tokens' in Python and list any two types.
Answer: Tokens are the smallest individual units or meaningful elements
in a Python program that the interpreter recognizes. Examples include
Keywords, Identifiers, Literals, Operators, and Punctuators.
Q2. What is the difference between Interactive Mode and Script
Mode?
Answer: Interactive Mode executes commands line-by-line and gives
immediate results, making it ideal for testing small code snippets. Script
Mode is used for writing lengthy programs that can be saved as a .py file
and executed later.
3-Marker Questions
Q1. List and explain any three features of Python. Answer:
1. Simple and Easy to Learn: Python has a clear, English-like syntax
that reduces the complexity of coding.
2. Platform Independent: Python code can run on various operating
systems like Windows, Linux, or macOS without modification.
3. Interpreted Language: Python code is executed line-by-line by an
interpreter, which makes debugging easier.
Q2. Explain the rules for naming a variable in Python. Answer:
A variable name must start with a letter (A-Z, a-z) or an underscore
(_).
It can contain letters, digits (0-9), and underscores, but no other
special characters are allowed.
It cannot be a reserved Python keyword, such as if, else, or while.
5-Marker Questions
Q1. Discuss the various types of Literals supported in Python with
examples.
Answer: Literals represent fixed values stored in variables. The types
include:
String Literals: Text enclosed in single, double, or triple quotes.
E.g., "Hello", '''Multiline'''.
Numeric Literals: Includes Integers (whole numbers like 10),
Floats (decimal numbers like 10.5), and Complex numbers (like
2+3j).
Boolean Literals: Represents logical values: True or False.
None Literal: Used to indicate the absence of a value or a null
object.
Q2. Explain the use of print() and input() functions. How can you
format the output and handle numeric input? Answer:
print() Function: Used to display messages or variable values on
the screen.
Formatting Output: You can use a comma (,) to add spaces
between values, \t for tab spaces, and \n for new lines.
input() Function: Used to take input from the user during program
execution.
Numeric Input: Since input() always returns data as a string, it
must be converted using int() or float() for calculations. Example:
age = int(input("Enter age: "))