Python Practice – Questions & Answers
Beginner Level
Q16. Python data types.
int, float, str, list, tuple, dict, set
Q17. Take user input.
name = input("Enter name: ")Q18. Type conversion.
int("10")Q19. Single-line comment.
# This is a comment
Q20. Multi-line comment.
''' This is a comment '''
Intermediate Level
Q21. Reduce function.
from functools import reduce reduce(lambda a,b:a+b, nums)
Q22. String slicing.
name[0:3]
Q23. String methods.
upper(), lower(), strip(), split()
Q24. Dictionary keys.
user.keys()
Q25. Dictionary values.
user.values()
Advanced Level
Q26. Encapsulation.
Data hiding.
Q27. __str__ method.
def __str__(self):
return self.name
Q28. Generator function.
def gen():
yield 1
Q29. Decorator.
Function modifying another function.
Q30. Decorator example.
def mydec(func):
def wrap():
func()
return wrap
No comments:
Post a Comment