Unit summary

  • Python is an interpreted, dynamically typed language created by Guido van Rossum.
  • Indentation marks blocks and # starts a comment.
  • Identifiers are case sensitive, and keywords are reserved.
  • Operator precedence decides the order of evaluation.
  • The basic types are int, float, complex, bool and str.
  • int() and float() convert explicitly, and mixed arithmetic converts implicitly.
  • input() returns a string, and print() controls output with sep and end.
  • Strings are immutable sequences with indices from 0 and from -1.
  • Methods such as upper(), find(), replace() and count() return new values.
  • Slicing, split(), join() and f-strings process and format text.

Glossary

Term Meaning
Data type The kind of value, such as int or str.
Escape sequence A backslash code such as \n for a new line.
Expression A combination of values and operators giving a value.
f-string A string with embedded expressions in braces.
Identifier A name given to a variable or function.
Immutable Not changeable after creation.
Indentation Space at the start of a line that marks a block.
Index The position of a character, starting at 0.
input() A function that reads a line from the user as a string.
Interpreter A program that runs Python code line by line.
join() A method that combines items into one string.
Keyword A reserved word with a fixed meaning.
Operator A symbol that performs an action on values.
Precedence The order in which operators are applied.
print() A function that displays values.
Slice A part of a sequence taken with start, stop and step.
split() A method that breaks a string into a list of words.
Statement An instruction executed by the interpreter.
String An immutable sequence of characters.
Type conversion Changing a value from one type to another.

Question bank

Short Answer Questions (2 marks each)

  1. Who created Python and when?
  2. What are identifiers? State the rules for naming them.
  3. What are keywords?
  4. State the precedence of arithmetic operators.
  5. Name the basic data types of Python.
  6. What is implicit type conversion?
  7. What does input() return?
  8. What is the use of the sep argument in print()?
  9. Why are strings called immutable?
  10. What is slicing?

Medium Answer Questions (5 marks each)

  1. Explain the features and application areas of Python.
  2. Explain the structure of a Python program.
  3. Explain the operators of Python with their precedence.
  4. Explain data types and type conversion with examples.
  5. Explain any six built-in methods of strings.
  6. Explain string slicing, joining and formatting with examples.

Long Answer Questions (15 marks each)

  1. Explain the history, features and structure of Python. Write a program to read the radius of a circle and print its area with two decimals.
  2. Explain the operators in Python with their precedence, and evaluate 10 + 4 3 * 2 // 6 - 5 % 3.
  3. Explain the basic data types and type conversion. Write a program to read two numbers as strings, convert them and print their sum.
  4. Explain strings and their built-in methods. Write a program to count the vowels in a string and print it in reverse using slicing.

Sources

  • Official BCA syllabus Python Programming, course code 26BCA403SEC01, Unit I