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)
- Who created Python and when?
- What are identifiers? State the rules for naming them.
- What are keywords?
- State the precedence of arithmetic operators.
- Name the basic data types of Python.
- What is implicit type conversion?
- What does input() return?
- What is the use of the sep argument in print()?
- Why are strings called immutable?
- What is slicing?
Medium Answer Questions (5 marks each)
- Explain the features and application areas of Python.
- Explain the structure of a Python program.
- Explain the operators of Python with their precedence.
- Explain data types and type conversion with examples.
- Explain any six built-in methods of strings.
- Explain string slicing, joining and formatting with examples.
Long Answer Questions (15 marks each)
- 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.
- Explain the operators in Python with their precedence, and evaluate 10 + 4 3 * 2 // 6 - 5 % 3.
- Explain the basic data types and type conversion. Write a program to read two numbers as strings, convert them and print their sum.
- 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
