TN Online TestSamacheer Kalvi practice

Python Variables and Operators: One Mark Questions, Book Back Answers and Notes

12th Standard · Computer Science · #5

Unit 5 is where Python programming begins. It covers interactive and script modes, the input() and print() functions, comments, indentation, tokens (identifiers, keywords, operators, delimiters and literals), the operators Python provides, and the basic data types: numbers, Boolean and strings.

Study this chapter

Asked in previous board exams

8 questions from this chapter came in 7 past public exams. Open any of them to see the answer and explanation.

  1. March 2026
    Which key is used to execute Python Script?
    See answer in the solved paper →
  2. March 2026
    Which of the following is the output of the given Python code if the value of a is 52?
    x="even" if a%2==0 else "odd"
    print(x)
    See answer in the solved paper →
  3. March 2025
    Which operator is also called as conditional operator?
    See answer in the solved paper →
  4. March 2024
    Which key is pressed to execute Python Script ?
    See answer in the solved paper →
  5. March 2023
    Which of the following is not a keyword in Python ?
    See answer in the solved paper →
  6. May 2022
    Which Operator is also called as Comparative Operator ?
    See answer in the solved paper →
  7. Supplementary 2021
    Which one of the following character is used to give a single line comments in Python program ?
    See answer in the solved paper →
  8. March 2020
    Expand IDLE :
    See answer in the solved paper →

About Python Variables and Operators

Medium ~90 min study

After four units of algorithms written in pseudo-code, this chapter moves to real Python. You learn how to open IDLE, type a command at the >>> prompt and see the answer at once, and how to save a longer program as a .py file and run it.

The chapter then goes through the smallest pieces a Python statement is made of. The interpreter breaks each line into tokens: identifiers, keywords, operators, delimiters and literals. You learn the rules for naming identifiers, how operators combine values into expressions, and which data types those values can have. Python groups statements by indentation instead of curly braces, so the spacing of your code is part of its meaning.

Book back questions here are usually short and exact: is a given name a valid identifier, what does 100 // 30 give, which operator is the ternary operator, what does input() return. Try each operator in interactive mode with the textbook values a = 100 and b = 10 and you will remember the outputs far better than by reading them.

What you'll learn

  • Run Python code in both interactive mode and script mode in IDLE.
  • Decide whether a given name is a valid identifier.
  • Use input() and print() to read and display data, converting input to numbers where needed.
  • Indent a block of statements correctly.
  • Work out the result of arithmetic, relational, logical and conditional expressions.
  • Identify integer, floating point, complex, Boolean and string values.

Before you start

  • The idea of an algorithm as a sequence of steps.
  • Basic computer use: opening programs and saving files in folders.
  • A basic idea of a variable as a name that holds a value.

Topics covered in this chapter

Interactive Mode Commands are typed at the >>> prompt and the result appears immediately. Useful for testing expressions.
Script Mode Code is written in a file saved with the .py extension and run with Run Module or F5, so the program can be edited and reused.
input() and print() input() reads what the user types and returns it as a string; print() evaluates expressions and displays the result.
Tokens The five smallest units of a Python statement: identifiers, keywords, operators, delimiters and literals.
Identifier Rules An identifier starts with a letter or underscore, may contain digits after that, is case sensitive, cannot be a keyword and cannot use symbols like %, $ or @.
Indentation Spaces or tabs mark a block of code in place of curly braces, and every statement in one block must have the same indentation.
Operators Arithmetic, relational, logical, assignment and conditional (ternary) operators, which act on operands to form expressions.
Data Types Numbers (integer, floating point and complex), Boolean values True and False, and strings of characters in quotes.

Python Variables and Operators explained

Python Basics: Modes, Tokens, Operators and Data Types

Interactive Mode and Script Mode

Python can be used in two modes. In interactive mode you type an expression or statement at the >>> prompt and the interpreter shows the result immediately. Typing 5 + 50 * 10 prints 505. This mode is good for testing small pieces of code. In script mode you write a program in a file (File, then New File in IDLE), save it with the .py extension and run it with Run, then Run Module, or by pressing F5. A saved script can be edited and run again as often as you like.

Input and Output

print() displays output. It evaluates any expression before printing, so print("The sum =", x + y) shows the computed sum. input() reads what the user types and always returns it as a string. To do arithmetic with it, convert it first: x = int(input("Enter a number: ")).

Comments and Indentation

A comment starts with the hash symbol #; the interpreter ignores everything after it on that line. Multi-line comments are written inside triple quotes. Python uses whitespace (spaces and tabs) to mark blocks of code such as the body of an if or a loop. Every statement in a block must be indented by the same amount, or the interpreter reports an error.

Tokens

The interpreter splits each line into tokens. There are five kinds. Identifiers are names for variables, functions and objects. Keywords are reserved words such as if, else and while that cannot be used as identifiers. Operators are symbols that perform operations on values. Delimiters are characters such as ( ) [ ] { } , : that separate and group parts of a statement. Literals are raw data values, such as numeric, string and Boolean literals.

Operators

With a = 100 and b = 10: the arithmetic operators give a + b = 110, a / b = 10.0, a % 30 = 10, a ** 2 = 10000 and a // 30 = 3. Relational operators (== != > < >= <=) compare values and return True or False. Logical operators are and, or and not. Assignment operators include = and shorthand forms like x += 20, which means x = x + 20. The conditional (ternary) operator picks one of two values in a single line: min = a if a < b else b.

Data Types

Every value in Python is an object with a data type. The textbook covers three: numbers, Boolean and strings. Numbers are further divided into integers (such as 102), floating point numbers (such as 3.14) and complex numbers (such as 1 + 2j). A Boolean value is either True or False. A string is a sequence of characters enclosed in single, double or triple quotes.

Common mistakes to avoid

  • Starting an identifier with a digit or using symbols like $ or @. Names such as 1total or my$ are invalid; total1 and _my are valid.
  • Forgetting that input() returns a string. "5" + "3" gives "53", not 8; use int() or float() before calculating.
  • Indenting statements in the same block by different amounts, or mixing tabs and spaces. Keep the same indentation, commonly four spaces, throughout a block.
  • Using = when comparing values. A single = assigns a value; == checks whether two values are equal.
  • Mixing up / and //. 100 / 30 gives 33.333..., while 100 // 30 gives 3, because // rounds the result down to a whole number.

Test yourself on these with the practice test, then check the worked reasoning in the solved MCQs.

Frequently asked questions

What is the difference between interactive mode and script mode?

In interactive mode you type one statement at the >>> prompt and see its result straight away, which is handy for testing. In script mode you write a whole program in a .py file, save it and run it with F5, so it can be run again without retyping.

How do you name a variable correctly in Python?

Start with a letter (A to Z, a to z) or an underscore, then use letters, digits or underscores. Names are case sensitive, so Sum and sum are different. You cannot use a keyword such as if, and you cannot include spaces or symbols such as %, $ or @.

Why does input() cause problems in calculations?

input() always returns a string, even if the user types a number. Adding two such values joins the strings, and mixing a string with a number raises a TypeError. Convert first, for example n = int(input()).

How does Python use indentation to group statements?

Python has no curly braces for blocks. The statements that belong to an if, a loop or a function are indented, and all of them must be indented by the same amount. If the indentation does not match, the interpreter reports an IndentationError.

What is the conditional operator in Python?

It is the ternary operator, written as value_if_true if condition else value_if_false. For example, big = a if a > b else b stores the larger of a and b. It does in one line what an if..else statement does in several.

How do you write comments in Python?

A single-line comment starts with #, and the interpreter ignores the rest of that line. For comments over several lines, the textbook encloses the text in triple quotes at the start and the end.

What are escape sequences?

Escape sequences are characters preceded by a backslash that have a special meaning inside a string. \n starts a new line and \t inserts a horizontal tab. For example, print("Hello\nWorld") prints Hello and World on separate lines.

Last updated 15 September 2026

More chapters in Computer Science

View all
1 Function 2 Data Abstraction 3 Scoping 4 Algorithmic Strategies 6 Control Structures 7 Python Functions 8 Strings and String Manipulation 9 Lists, Tuples, Sets and Dictionary 10 Python Classes and Objects 11 Database Concepts 12 Structured Query Language (SQL) 13 Python and CSV Files 14 Importing C++ Programs in Python 15 Data Manipulation through SQL 16 Data Visualization using Pyplot: Line Chart, Pie Chart and Bar Chart