suggestions/python
Suggestions : Python (Class Basis)
Python & Django Assessment (75 Questions)
Class 1-4: Core Python Fundamentals
1. What is the correct way to check if Python is installed on your system?
a) python --install
b) python --version
c) python --check
d) python --status
Answer: b
2. True/False: In VS Code, you need to manually type the full path to Python every time you run a script.
Answer: False
3. Which of these is NOT a valid Python variable name?
a) my_variable
b) _private
c) 2nd_value
d) firstName
Answer: c
4. What is the output of print(10 // 3)?
a) 3.333
b) 3
c) 4
d) 3.0
Answer: b
5. True/False: A list is mutable, while a tuple is immutable.
Answer: True
6. Which data type would you use to store an ordered, unchangeable sequence of items?
a) List
b) Dictionary
c) Tuple
d) Set
Answer: c
7. What is the main difference between a list and a set?
a) Lists are ordered, sets are unordered
b) Lists can contain duplicates, sets cannot
c) Both a and b
d) Neither a nor b
Answer: c
Class 5-8: Intermediate Python Concepts
8. How do you access the value associated with the key 'name' in a dictionary person?
a) person('name')
b) person['name']
c) person.key('name')
d) person.getKey('name')
Answer: b
9. True/False: Strings in Python are mutable.
Answer: False
10. What will "Hello"[:2] return?
a) "He"
b) "Hel"
c) "llo"
d) "Hello"
Answer: a
11. What is the output of this code?
x = 5 if x > 2: print("A") elif x > 3: print("B") else: print("C")
a) A
b) B
c) C
d) A and B
Answer: a
12. Which loop is best when you know how many times you want to iterate?
a) for loop
b) while loop
c) Both are equally good
d) Neither
Answer: a
13. What does the break statement do in a loop?
a) Skips the current iteration
b) Exits the loop entirely
c) Restarts the loop
d) Continues to the next iteration
Answer: b
14. True/False: A function in Python must always return a value.
Answer: False
Class 9-12: Object-Oriented Programming & Databases
15. What is the output of this recursive function?
def factorial(n): if n == 1: return 1 else: return n * factorial(n-1) print(factorial(4))
a) 24
b) 10
c) 12
d) 6
Answer: a
16. Which keyword is used to create an anonymous function in Python?
a) def
b) function
c) lambda
d) anon
Answer: c
17. What will this code output?
try: print(10 / 0) except ZeroDivisionError: print("Error") else: print("Success")
a) Error
b) Success
c) Error Success
d) Nothing
Answer: a
18. True/False: The finally block in exception handling always executes, regardless of whether an exception occurred.
Answer: True
19. Which mode would you use to open a file for reading only?
a) "r"
b) "w"
c) "a"
d) "r+"
Answer: a
20. What is the correct way to ensure a file is properly closed after operations?
a) Using file.close()
b) Using the with statement
c) Both a and b
d) Files close automatically
Answer: b
21. In OOP, what is a class?
a) An instance of an object
b) A blueprint for creating objects
c) A specific variable type
d) A function that returns objects
Answer: b
22. What is the special method called that is automatically executed when a new object is created?
a) __init__
b) __main__
c) __self__
d) __new__
Answer: a
23. True/False: In Python, you can create private variables that cannot be accessed outside the class.
Answer: True (by convention using _ or __)
24. Which SQL database is commonly used with Django and comes built-in for development?
a) MySQL
b) PostgreSQL
c) SQLite
d) Oracle
Answer: c
25. What Python library is commonly used to connect to a MySQL database?
a) mysql-python
b) mysql-connector-python
c) pymysql
d) Both b and c
Answer: d
Class 13-16: Web Fundamentals & Introduction to Django
26. True/False: Python code runs directly in web browsers like JavaScript.
Answer: False
27. Which of these is NOT a Python web framework?
a) Django
b) Flask
c) React
d) FastAPI
Answer: c
28. What does MVT stand for in Django?
a) Model, View, Template
b) Model, Variable, Template
c) Main, View, Test
d) Model, View, Test
Answer: a
29. Which file in a Django project contains the main URL configuration?
a) views.py
b) models.py
c) urls.py
d) settings.py
Answer: c
30. What command do you use to start a new Django project?
a) django startproject myproject
b) django-admin startproject myproject
c) python startproject myproject
d) django createproject myproject
Answer: b
31. True/False: Django follows the DRY (Don't Repeat Yourself) principle.
Answer: True
32. Which command runs the Django development server?
a) python manage.py run
b) python manage.py start
c) python manage.py runserver
d) python manage.py server
Answer: c
Class 17-21: Advanced Django Concepts
33. Where do you define the structure of your database tables in Django?
a) views.py
b) urls.py
c) models.py
d) admin.py
Answer: c
34. After creating or modifying a model, what two commands must you run?
a) migrate and runserver
b) makemigrations and migrate
c) createmigrations and migrate
d) migrations and sqlmigrate
Answer: b
35. True/False: The Django admin interface is automatically available for all models without any configuration.
Answer: False
36. Which file do you use to register your models with the Django admin?
a) models.py
b) views.py
c) admin.py
d) apps.py
Answer: c
37. What is the purpose of the __str__ method in a Django model?
a) To define database relationships
b) To provide a string representation of the object
c) To validate form data
d) To handle URL routing
Answer: b
38. In URL patterns, what does <int:pk> represent?
a) A string parameter
b) An integer primary key parameter
c) A template variable
d) A database query
Answer: b
39. True/False: Function-Based Views (FBV) and Class-Based Views (CBV) can both be used in Django.
Answer: True
40. Which template tag is used for inheritance in Django templates?
a) {% block %}
b) {% extends %}
c) {% include %}
d) {% load %}
Answer: b
41. How do you output a variable in a Django template?
a) {{ variable }}
b) {% variable %}
c) {{% variable %}}
d) { variable }
Answer: a
42. What is the purpose of the {% for %} template tag?
a) To create conditional statements
b) To loop through a list of items
c) To define template blocks
d) To include other templates
Answer: b
43. True/False: Django forms can handle validation automatically.
Answer: True
44. Which decorator would you use to restrict access to a view to logged-in users only?
a) @login_required
b) @authenticated_only
c) @user_required
d) @login_only
Answer: a
45. What is CSRF protection used for in Django?
a) Preventing SQL injection attacks
b) Preventing cross-site request forgery attacks
c) Preventing cross-site scripting attacks
d) Preventing clickjacking
Answer: b
Class 22-24: Mini Project Implementation
46. In the blog project, what relationship should a Post model have with a Category model if a post can have multiple categories?
a) OneToOneField
b) ForeignKey
c) ManyToManyField
d) CharField
Answer: c
47. True/False: In Django, you need to write raw SQL queries to interact with the database.
Answer: False
48. Which command creates a superuser for the Django admin?
a) python manage.py createsuperuser
b) python manage.py createadmin
c) python manage.py superuser
d) python manage.py adminuser
Answer: a
49. What is the purpose of the get_absolute_url method in a Django model?
a) To redirect after form submission
b) To generate URLs for individual model instances
c) To validate URL patterns
d) To handle admin site URLs
Answer: b
50. Which setting should be changed to False before deploying a Django project to production?
a) ALLOWED_HOSTS
b) DEBUG
c) INSTALLED_APPS
d) DATABASES
Answer: b
51. True/False: Django's collectstatic command is used to collect all static files into a single directory for production.
Answer: True
Additional Mixed Questions (52-75)
52. Which of the following is a valid Python list?
a) [1, 2, 3]
b) (1, 2, 3)
c) {1, 2, 3}
d) {1: 'a', 2: 'b'}
Answer: a
53. What does the append() method do for a list?
a) Removes the last item
b) Adds an item to the beginning
c) Adds an item to the end
d) Sorts the list
Answer: c
54. True/False: A dictionary stores data in key-value pairs.
Answer: True
55. What is the output of "hello".upper()?
a) "HELLO"
b) "Hello"
c) "hello"
d) Error
Answer: a
56. Which operator is used for exponentiation in Python?
a) ^
b) **
c) //
d) %%
Answer: b
57. What will 3 != 4 evaluate to?
a) True
b) False
c) Error
d) None
Answer: a
58. True/False: The else clause in a loop executes only if the loop completed normally (without a break).
Answer: True
59. What is the scope of a variable defined inside a function?
a) Global
b) Local
c) Both
d) Neither
Answer: b
60. Which module is used for working with dates and times in Python?
a) datetime
b) time
c) calendar
d) date
Answer: a
61. True/False: In Python, all exceptions inherit from the BaseException class.
Answer: True
62. What does ORM stand for in Django?
a) Object-Role Modeling
b) Object-Relational Mapping
c) Object-Resource Management
d) Object-Runtime Manipulation
Answer: b
63. Which field would you use in a Django model to store a large text field?
a) CharField
b) TextField
c) StringField
d) LargeField
Answer: b
64. True/False: Django templates can contain Python code directly.
Answer: False
65. What is the purpose of Django's MEDIA_ROOT setting?
a) To define where static files are stored
b) To define where user-uploaded files are stored
c) To define the root URL of the media server
d) To define media queries for responsive design
Answer: b
66. Which HTTP method is typically used for retrieving data in web applications?
a) POST
b) GET
c) PUT
d) DELETE
Answer: b
67. True/False: Django's authentication system includes built-in views for login and logout.
Answer: True
68. What is the purpose of the on_delete parameter in a Django ForeignKey?
a) To specify what happens when the referenced object is deleted
b) To specify when to delete the field
c) To specify validation rules
d) To specify the database engine
Answer: a
69. Which template filter would you use to get the length of a list in Django templates?
a) {{ list|count }}
b) {{ list|length }}
c) {{ list|size }}
d) {{ list|items }}
Answer: b
70. True/False: Django's @login_required decorator automatically redirects users to the login page if they're not authenticated.
Answer: True
71. What is the purpose of Django's settings.py file?
a) To define URL patterns
b) To define database models
c) To store project configuration
d) To handle HTTP requests
Answer: c
72. Which command would you use to create a new Django app?
a) python manage.py newapp myapp
b) python manage.py createapp myapp
c) django-admin startapp myapp
d) python manage.py startapp myapp
Answer: d
73. True/False: Django comes with built-in protection against SQL injection attacks.
Answer: True
74. What is the purpose of the context parameter in Django's render() function?
a) To specify the template to use
b) To pass data to the template
c) To handle HTTP requests
d) To define URL patterns
Answer: b
75. Which Django component is responsible for handling browser requests and returning responses?
a) Models
b) Templates
c) Views
d) URLs
Answer: c
Answer Key Summary
1-b, 2-False, 3-c, 4-b, 5-True, 6-c, 7-c, 8-b, 9-False, 10-a, 11-a, 12-a, 13-b, 14-False, 15-a, 16-c, 17-a, 18-True, 19-a, 20-b, 21-b, 22-a, 23-True, 24-c, 25-d, 26-False, 27-c, 28-a, 29-c, 30-b, 31-True, 32-c, 33-c, 34-b, 35-False, 36-c, 37-b, 38-b, 39-True, 40-b, 41-a, 42-b, 43-True, 44-a, 45-b, 46-c, 47-False, 48-a, 49-b, 50-b, 51-True, 52-a, 53-c, 54-True, 55-a, 56-b, 57-a, 58-True, 59-b, 60-a, 61-True, 62-b, 63-b, 64-False, 65-b, 66-b, 67-True, 68-a, 69-b, 70-True, 71-c, 72-d, 73-True, 74-b, 75-c
Comments
Post a Comment