Question 1
Answer
Escape sequences are special character
combinations beginning with a backslash
(\) that are used to represent special
characters or formatting within a Python string.
| Escape Sequence | Meaning | Example |
|---|---|---|
\n |
New line | "Hello\nWorld" |
\t |
Horizontal tab | "Name\tAge" |
\\ |
Backslash character | "C:\\Users" |
\" |
Double quotation mark | "He said \"Hello\"" |
print("Hello\nPython")
Output:
Hello
Python
Question 2
Answer
Any two important rules are:
-
A variable name must begin with a
letter (A–Z or a–z) or an underscore
(
_). It cannot begin with a digit. - A variable name can contain letters, digits and underscores, but spaces and other special characters are not allowed.
name = "Anant"
student_1 = "Riya"
_age = 14
Invalid:
1student = "Riya"
student name = "Riya"
age and Age are different names.
Python keywords such as if, for
and class cannot be used as variable names.
Question 3
Answer
The assignment operator (=)
is used to assign a value or the result of an expression
to a variable.
age = 13
name = "Riya"
total = 25 + 15
Here, 13 is assigned to age,
"Riya" is assigned to name,
and the result of 25 + 15 is assigned to
total.
The assignment operator should not be confused with the
equality comparison operator ==.
| Operator | Purpose | Example |
|---|---|---|
= |
Assignment | x = 10 |
== |
Checks whether two values are equal | x == 10 |
Question 4
Answer
1. print() Function
The print() function is used to display
information or output on the screen.
print("Welcome to Python")
print(25)
Output:
Welcome to Python
25
2. input() Function
The input() function is used to accept data
from the user through the keyboard. It returns the entered
value as a string unless the value is
explicitly converted to another data type.
name = input("Enter your name: ")
print("Hello", name)
age = int(input("Enter your age: "))
print(age)
Here, int() converts the string returned by
input() into an integer.
| Function | Purpose |
|---|---|
print() |
Displays output to the user. |
input() |
Accepts input from the user. |
Question 5
Answer
| Data Type | Example 1 | Example 2 |
|---|---|---|
Integer (int) |
25 |
-10 |
String (str) |
"Hello" |
"Python" |
marks = 95
temperature = -10
name = "Riya"
language = "Python"
The first two values are integers, while the last two values are strings.
Quick Revision
| Question | Key Answer |
|---|---|
| 1 |
Escape sequences begin with \ and represent
special characters or formatting in strings.
|
| 2 | Variable names must start with a letter or underscore and may contain letters, digits and underscores. |
| 3 |
= assigns a value or expression result to
a variable.
|
| 4 |
print() displays output; input()
accepts user input.
|
| 5 |
Integers: 25, -10;
Strings: "Hello", "Python".
|