0% found this document useful (0 votes)
8 views3 pages

Python Exam Full Examples

The document outlines key concepts in Python programming, including data types, operators, loops, and string manipulation. It provides examples for various topics such as string slicing, list methods, and the differences between lists and tuples. Additionally, it highlights Python's key features and the importance of indexing and string methods.

Uploaded by

mahidur1224
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Python Exam Full Examples

The document outlines key concepts in Python programming, including data types, operators, loops, and string manipulation. It provides examples for various topics such as string slicing, list methods, and the differences between lists and tuples. Additionally, it highlights Python's key features and the importance of indexing and string methods.

Uploaded by

mahidur1224
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MODULE 1

5-Mark Questions

1. Explain different data types in Python with examples.


Python supports the following data types with examples:
- int: x = 10
- float: pi = 3.14
- complex: c = 2+3j
- string: name = "Python"
- list: nums = [1,2,3]
- tuple: t = (10,20,30)
- dictionary: d = {"name":"Rahul","age":20}
- set: s = {1,2,3}

2. Types of operators:
Arithmetic (+,-,*,/,//,%,**)
Example: 5+3 = 8
Relational (==,!=,>,<,>=,<=)
Example: 5>3 → True
Logical (and, or, not)
Example: True and False → False
Assignment (=,+=,-=,*=)
Bitwise (&,|,^,~,<<,>>)
Membership (in, not in)
Identity (is, is not)

3. Working of loops:
while example:
i=1
while i<=5:
print(i)
i+=1

for loop example:


for x in [1,2,3]:
print(x)

3-Mark Questions

4. Structure of if-else:
if condition:
print("True")
else:
print("False")

5. break, continue, pass examples:


for i in range(5):
if i==3:
break

for i in range(5):
if i==2:
continue

for i in range(5):
pass

6. Key features of Python:


Simple, interpreted, portable, object-oriented, dynamic typing.

MODULE 2
5-Mark Questions

7. String slicing examples:


s = "PYTHON"
s[0:3] → PYT
s[:4] → PYTH
s[2:] → THON
s[::2] → PTO
s[::-1] → NOHTYP

8. Five string methods:


"python".upper() → PYTHON
"HELLO".lower() → hello
"apple".find('p') → 1
"hello world".replace("world","Python") → hello Python
"a b c".split() → ['a','b','c']

9. String immutability:
s = "Hello"
s[0] = 'J' → Error

3-Mark Questions:

10. Importance of indexing:


Used to access characters for slicing.
11. find vs replace:
find() returns index; replace() returns new string.

12. split importance:


Breaks string into list for processing.

MODULE 3
5-Mark Questions

13. List methods:


l = [1,2,3]
[Link](4)
[Link](1,10)
[Link](2)
[Link](1)
[Link]()

14. List vs Tuple:


List mutable, Tuple immutable.

15. Dictionary:
d = {"name":"Rahul","age":20}
d["name"]
d["age"]=25
del d["age"]

3-Mark Questions

16. Purpose of lists:


Store multiple items dynamically.

17. Tuple slicing:


t = (10,20,30,40)
t[1:3] → (20,30)

18. get() vs direct access:


[Link]("age") safer than d["age"]

You might also like