Python Introduction Q&A
2 Marks Question
Q1. What is Python? Mention any two features of Python.
Answer:
Python is a high-level, interpreted, and general-purpose programming language that is easy to learn and widely used for developing applications, web development, data analysis, artificial intelligence, and automation.
Any two features of Python are:
-
Easy to Learn and Use:
Python has a simple and readable syntax, making it easy for beginners to learn and write programs.
-
Platform Independent:
Python programs can run on different operating systems such as Windows, Linux, and macOS without requiring major changes.
Q2. Who developed Python and when was it released?
Answer:
Python was developed by Guido van Rossum, a Dutch programmer. It was first released in 1991.
Python was designed to be a simple, readable, and easy-to-learn programming language, making it one of the most popular programming languages in the world today.
Q3. What is an Identifier in Python?
Answer:
An identifier is a name used to identify variables, functions, classes, modules, or other objects in a Python program. Identifiers help programmers refer to these elements while writing code.
Examples of Valid Identifiers:
student_nametotalMarks_age
Rules for Identifiers:
- An identifier must begin with a letter (A–Z or a–z) or an underscore (_).
- It cannot begin with a digit.
- It can contain letters, digits, and underscores.
- Python keywords cannot be used as identifiers.
Q4. What are Keywords in Python?
Answer:
Keywords are reserved words in Python that have predefined meanings and are used to perform specific functions in a program. Keywords cannot be used as identifiers such as variable names, function names, or class names.
Examples of Python Keywords:
ifelseforwhileTrueFalsedefclass
Example:
if marks >= 40:
print("Pass")
In the above example, if is a Python keyword
used for decision-making.
Q5. What is a Variable?
Answer:
A variable is a named memory location used to store data or values in a Python program. The value stored in a variable can be changed during program execution.
Example:
name = "Hardik"
age = 20
marks = 85.5
In the above example, name, age, and marks are variables that store different types of data.
Q6. What is the purpose of the print() function?
Answer:
The print() function in Python is used to
display output on the screen. It is commonly used to display
text, numbers, variables, expressions, and the results of calculations.
Example:
name = "Hardik"
print("Welcome", name)
Output:
Welcome Hardik
The print() function helps programmers display
information to the user and verify the output of a program.
Q7. What is the purpose of the input() function?
Answer:
The input() function in Python is used to
accept input from the user during program execution.
By default, the value entered by the user is stored as a
string (str).
Example:
name = input("Enter your name: ")
print("Welcome", name)
Sample Output:
Enter your name: Hardik
Welcome Hardik
The input() function allows a program to
interact with the user by accepting values such as names, numbers,
or other information at runtime.
Q8. Name any four basic data types in Python.
Answer:
Python provides several built-in data types for storing different kinds of data. Any four basic data types are:
-
int (Integer):
Used to store whole numbers.
Example:25 -
float (Floating Point):
Used to store decimal numbers.
Example:85.5 -
str (String):
Used to store text or characters enclosed in single or double quotes.
Example:"Python" -
bool (Boolean):
Used to store logical values, either True or False.
Example:True
Q9. Differentiate between int and float data types.
Answer:
int
|
float
|
|---|---|
| int (Integer) is used to store whole numbers without a decimal point. | float (Floating Point) is used to store numbers with decimal points. |
Example: 25, 100, -15
|
Example: 25.5, 3.14, -7.8
|
It occupies less memory than a float value.
|
It generally occupies more memory than an integer value. |
Q10. What are Comments in Python?
Answer:
Comments are explanatory notes written in a Python program to make the code easier to understand. They are ignored by the Python interpreter and are not executed as part of the program.
-
Single-line comments begin with the
#symbol. -
Multi-line comments can be written using triple quotes
(
''' '''or""" """).
Examples:
# This is a single-line comment
print("Hello, World!")
"""
This is a
multi-line comment.
"""
Comments improve the readability of a program and help programmers understand the purpose and logic of the code.
3 Marks Question
Q1. Explain the features of Python.
Answer:
Python is a high-level, interpreted, and general-purpose programming language. It is widely used because of its simplicity, readability, and powerful features.
Some important features of Python are:
-
Easy to Learn and Use:
Python has a simple and readable syntax, making it easy for beginners to learn and write programs.
-
Interpreted Language:
Python executes code line by line using an interpreter, making debugging and testing easier.
-
Platform Independent:
Python programs can run on different operating systems such as Windows, Linux, and macOS without modification.
-
Object-Oriented:
Python supports Object-Oriented Programming (OOP), allowing programs to be developed using classes and objects.
-
Open Source:
Python is free to download, use, and distribute. Its source code is publicly available.
-
Large Standard Library:
Python provides a rich collection of built-in modules and libraries for tasks such as web development, data analysis, machine learning, and file handling.
Conclusion:
Due to its simplicity, portability, extensive libraries, and powerful features, Python is one of the most popular programming languages used in education, web development, artificial intelligence, data science, and software development.
Q2. Explain the rules for naming identifiers in Python.
Answer:
An identifier is a name given to variables, functions, classes, modules, or other objects in a Python program. Python follows certain rules for naming identifiers.
Rules for Naming Identifiers:
-
Must begin with a letter or an underscore (_):
An identifier should start with an alphabet (A–Z or a–z) or an underscore (
_). It cannot begin with a digit. -
Can contain letters, digits, and underscores:
After the first character, an identifier may contain letters, numbers (0–9), and underscores (
_). -
Cannot contain special characters or spaces:
Special symbols such as
@,#,$,%,-, and spaces are not allowed in identifiers. -
Keywords cannot be used as identifiers:
Reserved words (keywords) such as
if,else,while,for, andclasscannot be used as identifiers. -
Python is case-sensitive:
Identifiers such as
Marks,marks, andMARKSare considered different.
Examples:
Valid Identifiers:
student_name_markstotal1RollNo
Invalid Identifiers:
2namestudent-namemy nameclass
Q3. Explain different data types in Python with examples.
Answer:
Data types specify the type of data that a variable can store in a Python program. Python provides several built-in data types. The four basic data types are as follows:
1. Integer (int)
The int data type is used to store whole numbers without a decimal point.
Example:
age = 18
marks = 95
2. Float (float)
The float data type is used to store numbers with decimal values.
Example:
percentage = 89.5
price = 250.75
3. String (str)
The str data type is used to store text or a sequence of characters enclosed in single or double quotes.
Example:
name = "Hardik"
city = 'Surat'
4. Boolean (bool)
The bool data type is used to store logical values. It has only two possible values: True and False.
Example:
result = True
isPresent = False
Summary Table
| Data Type | Description | Example |
|---|---|---|
| int | Stores whole numbers | 25, 100, -15 |
| float | Stores decimal numbers | 3.14, 85.5 |
| str | Stores text or characters | "Python", 'Hello' |
| bool | Stores logical values | True, False |
Q4. What is the difference between Syntax Error and Logical Error?
Answer:
Errors are mistakes in a program that prevent it from working correctly. Two common types of errors in Python are Syntax Errors and Logical Errors.
| Syntax Error | Logical Error |
|---|---|
| A syntax error occurs when the rules (syntax) of the Python language are violated. | A logical error occurs when the program runs successfully but produces an incorrect output due to wrong logic. |
| The program cannot execute until the syntax error is corrected. | The program executes without any error message but gives incorrect results. |
| These errors are detected by the Python interpreter during execution. | These errors are identified by testing and debugging the program. |
Example: Missing colon (:) after an if statement.
|
Example: Using + instead of * in a mathematical calculation.
|
Example of Syntax Error:
age = 18
if age >= 18
print("Eligible to Vote")
Error: Missing colon (:) after the
if statement.
Example of Logical Error:
length = 5
width = 4
area = length + width
print(area)
Correct Logic: The area should be calculated using
multiplication (length * width), not addition.
Q5. Explain input() and print() functions with examples.
Answer:
Python provides built-in functions to interact with the user.
The input() function is used to accept data from the user,
while the print() function is used to display output on the screen.
1. input() Function
The input() function is used to accept input
from the user during program execution. By default, the value entered by the
user is stored as a string (str).
Example:
name = input("Enter your name: ")
print("Welcome", name)
Sample Output:
Enter your name: Hardik
Welcome Hardik
2. print() Function
The print() function is used to display text,
variables, expressions, or the result of a program on the screen.
Example:
name = "Hardik"
age = 20
print("Name:", name)
print("Age:", age)
Output:
Name: Hardik
Age: 20
Q6. What is Type Conversion in Python?
Answer:
Type Conversion is the process of converting a value from one data type to another. Python supports two types of type conversion:
- Implicit Type Conversion: Performed automatically by Python.
-
Explicit Type Conversion (Type Casting):
Performed manually by the programmer using built-in functions such as
int(),float(),str(), andbool().
Common Type Conversion Functions:
int(): Converts a value to an integer.float(): Converts a value to a floating-point number.str(): Converts a value to a string.bool(): Converts a value to a Boolean value.
Example:
a = "25"
b = int(a)
x = 15
y = float(x)
print(b)
print(y)
Output:
25
15.0
Q7. Explain Arithmetic Operators in Python.
Answer:
Arithmetic operators are used to perform mathematical operations on numeric values such as addition, subtraction, multiplication, division, and finding the remainder.
Common Arithmetic Operators in Python:
| Operator | Description | Example |
|---|---|---|
+ |
Addition | 10 + 5 = 15 |
- |
Subtraction | 10 - 5 = 5 |
* |
Multiplication | 10 * 5 = 50 |
/ |
Division | 10 / 5 = 2.0 |
% |
Modulus (Remainder) | 10 % 3 = 1 |
// |
Floor Division | 10 // 3 = 3 |
** |
Exponentiation (Power) | 2 ** 3 = 8 |
Example:
a = 10
b = 3
print("Addition =", a + b)
print("Subtraction =", a - b)
print("Multiplication =", a * b)
print("Division =", a / b)
print("Modulus =", a % b)
print("Floor Division =", a // b)
print("Exponentiation =", a ** b)
Output:
Addition = 13
Subtraction = 7
Multiplication = 30
Division = 3.3333333333333335
Modulus = 1
Floor Division = 3
Exponentiation = 1000
Q8. Explain Relational Operators in Python.
Answer:
Relational operators (also called comparison operators) are used to compare two values or expressions. The result of a relational operation is always a Boolean value, i.e., True or False.
Common Relational Operators in Python:
| Operator | Description | Example |
|---|---|---|
== |
Equal to | 10 == 10 → True |
!= |
Not equal to | 10 != 5 → True |
> |
Greater than | 10 > 5 → True |
< |
Less than | 10 < 5 → False |
>= |
Greater than or equal to | 10 >= 10 → True |
<= |
Less than or equal to | 10 <= 5 → False |
Example:
a = 15
b = 10
print(a == b)
print(a != b)
print(a > b)
print(a < b)
print(a >= b)
print(a <= b)
Q9. Explain Boolean Data Type with Example.
Answer:
The Boolean data type (bool) is used to store
logical values in Python. It has only
two possible values: True and
False.
Boolean values are commonly used in decision-making, conditional statements, and loops to determine whether a condition is true or false.
Example:
result = True
isPresent = False
print(result)
print(isPresent)
Output:
True
False
Explanation:
Truerepresents a true condition.Falserepresents a false condition.-
Boolean values are often returned by comparison operators such as
==,>,<,>=, and<=.
Q10. Write a Python program to input a student's name and display a welcome message.
Answer:
The following Python program accepts the student's name as input using the
input() function and displays a welcome
message using the print() function.
Program:
# Program to input a student's name and display a welcome message
name = input("Enter Student Name: ")
print("Welcome", name)
Sample Output:
Enter Student Name: Hardik
Welcome Hardik
Explanation:
-
The
input()function is used to accept the student's name from the user. -
The entered name is stored in the variable
name. -
The
print()function displays a welcome message along with the student's name.


