🔄 Python Refresher

Review of Python Basics

पायथन की समीक्षा

⏱ 2 hr3 topicsInteractive
🎯 By the end: You can recall Python's data types, write conditionals and loops, and use strings, lists, tuples and dictionaries confidently before moving on.

Class 12 builds directly on the Python you learned in Class 11. Before we go further — into functions, files and stacks — let's blow the dust off the fundamentals. Skim what you remember, and run anything you're unsure about in the playground. If a section feels shaky, revisit the matching Class 11 chapter.

1Tokens, variables and data types

Recall the building blocks: keywords (reserved words), identifiers (names), literals (fixed values) and operators. Variables are created by assignment, and Python is dynamically typed — it infers the type from the value.

TypeExampleMutable?
int / float42, 3.14
str"hello"No (immutable)
list[1, 2, 3]Yes
tuple(1, 2, 3)No (immutable)
dict{"a": 1}Yes
Data types recap▶ runs real Python
main.py
Output
Click Run to execute.
Key points
  • Tokens: keywords, identifiers, literals, operators. Variables are created by assignment (dynamic typing).
  • Numbers (int/float), strings, tuples are immutable; lists and dictionaries are mutable.
  • type(x) reports the type of a value.

2Control flow and strings

Decisions use if / elif / else; repetition uses for (with range()) and while; break and continue alter the flow. Remember — Python uses indentation, not braces, to mark blocks.

Strings support indexing, slicing (s[start:stop:step]) and methods like upper(), lower(), split(), strip(), find() and replace() — and they're immutable, so every method returns a new string.

Control flow + strings▶ runs real Python
main.py
Output
Click Run to execute.
Key points
  • if/elif/else for decisions; for (with range) and while for loops; break/continue to control them.
  • Indentation defines blocks in Python.
  • Strings are immutable; slicing and methods return new strings.

3Lists, tuples and dictionaries

The three collections you'll use most:

  • List — ordered, mutable: append(), pop(), insert(), sort().
  • Tuple — ordered, immutable; great for fixed data and packing/unpacking.
  • Dictionary — key-value pairs, mutable: keys(), values(), items(), get().
Collections recap▶ runs real Python
main.py
Output
Click Run to execute.
Key points
  • List = ordered + mutable; Tuple = ordered + immutable; Dictionary = key-value + mutable.
  • Lists: append/pop/insert/sort. Dicts: keys/values/items/get. Tuples: packing/unpacking.
  • Loop a dictionary with for k, v in d.items().

★ Practical: warm-up program

In the playground, write one small program that:

  1. Stores three test marks in a list and prints their average.
  2. Uses an if/else to print 'pass' or 'fail' based on the average (pass mark 33).
  3. Stores a student's name and class in a dictionary and prints them with items().
  4. Reverses a string using slicing.

Ready for the chapter test?

Answer 5 questions. Score 60% or more to mark this chapter complete.

Start the test →

💡 Log in to save your progress and earn the certificate.