(Python Notes)
Unit 5
Introduction to Python
Writing Subjective Responses
1. Data Types in Python
Data types tell what type of value a variable stores.
Examples of data types are int, float, string, boolean, list, tuple, and dictionary.
2. Operators
Operators are symbols used to perform operations on values and variables.
Examples: + , - , * , / , > , < , ==
3. Single-line and Multi-line Comments
Single-line comment starts with # and is written in one line.
Multi-line comment is written using ''' ''' or """ """ and covers many lines.
4. Control Structures
Control structures control the flow of a program.
They include if-else, loops, and jump statements.
5. Explain the following:
a) append()
Adds an element at the end of a list.
b) clear()
Removes all elements from the list.
c) extend()
Adds multiple elements to a list.
d) pop()
Removes the last element from the list.
6. Slicing a String
Slicing means taking a part of a string using index numbers.
Short Answer Questions
1. Advantages and Disadvantages of Flowchart
Advantages
Easy to understand
Shows clear logic
Helps in error finding
Disadvantages
Time consuming
Difficult for large programs
Hard to modify
2. Operator Precedence
Operator precedence decides which operator is evaluated first.
3. Variable
A variable is a name given to a memory location to store a value.
4. Features of Python
Easy to learn
High-level language
Platform independent
5. Short Notes
a) Relational Operators
Used to compare values and return True or False.
b) Identifiers
Names given to variables, functions, etc.
c) Logical Operators
Used to combine conditions like and, or, not.
d) Sequence
An ordered collection of items like list, tuple, and string.
Long Answer Questions
1. Differences
a) For Loop and While Loop
For loop runs for a fixed number of times.
While loop runs until a condition becomes false.
b) Break and Continue
Break stops the loop.
Continue skips the current step.
c) Membership and Comparison Operators
Membership checks presence of an element.
Comparison checks equality or relation.
d) Syntax Error and Logical Error
Syntax error breaks language rules.
Logical error gives wrong output.
2. Importance of Indentation
Indentation shows the block of code in Python.
Wrong indentation causes errors.
3. Loops
Loops repeat a part of the program again and again.
4. String Built-in Functions
Some string functions are upper(), lower(), find(), replace().
5. Operations on a List
We can add, remove, sort, and slice elements in a list.
Application Based Answers (One-Line)
[Link] if-else
[Link]-else statement
[Link]-else statement
[Link] operator
[Link] quotes (''' ''')
[Link] of naming identifiers
[Link] and Logical operators