Plus Two Computer Science Short Answers

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

PLUS TWO COMPUTER SCIENCE SHORT ANSWERS

1. What is a variable in Python?


A named location in memory used to store data.

2. How are variables declared in Python?


By assigning a value using the '=' operator.

3. What is the naming convention for variables in Python?


Variables should start with a letter or underscore, followed by letters, digits, or
underscores.

4. How can you assign multiple values to multiple variables in one line?
By separating the values with commas and assigning them to respective variables.

5.. What is the modulus operator (%) used for in Python?


It returns the remainder of the division of two numbers.

6. Define the '==' operator in Python.


It checks if two values are equal.

7. What is the purpose of the 'and' operator in Python?


It returns True if both operands are True.

8. Explain the 'not' operator in Python.


It returns True if the operand is False and False if the operand is True.

9. What does the 'if' statement do in Python?


It executes a block of code if a specified condition is true.

10. What is the purpose of the 'for' loop?


It iterates over a sequence (such as a list, tuple, or string).

11. What is the 'elif' statement used for?


It allows checking for multiple conditions after an 'if' statement.

12. How does the 'while' loop work?


It executes a block of code repeatedly as long as a specified condition is True.

13. What is a function in Python?


A reusable block of code that performs a specific task.

14. How is a function defined in Python?


By using the 'def' keyword followed by the function name and parameters.

15. How are strings defined in Python?


By enclosing characters within single quotes ('') or double quotes ("").

16. What does string concatenation mean?


It is the process of combining two or more strings together.

17. Can you change a string after it's been created in Python?
No, strings are immutable in Python.

18. What does the 'len()' function do with strings?


It returns the length (number of characters) of a string.

19. What is a list in Python?


An ordered and mutable collection of elements.

20. How can you access elements in a list?


By using their index within square brackets [].

21. What method in Python is used to add an element to the end of a list?
The 'append()' method.

22: How can you check if an element is present in a list?


By using the 'in' keyword.

23. Define a tuple in Python.


An ordered and immutable collection of elements.

24. How are tuples different from lists?


Tuples are immutable, while lists are mutable.

25.How can you join two or more tuples in Python?


By using the '+' operator to concatenate them.

26: Is it possible to modify elements in a tuple after it's been created?


No, tuples are immutable.
27. Define a set in Python.
An unordered collection of unique elements.

28. How are sets different from lists?


Sets do not allow duplicate elements, while lists do.

29. What does the 'union()' method do with sets in Python?


It returns a new set containing all unique elements from both sets.

30. How do sets handle duplicate elements?


Sets automatically remove duplicate elements.

31. What is a dictionary in Python?


A collection of key-value pairs.

32. How are dictionaries accessed?


By using keys to retrieve their associated values.

33. What happens if you try to access a key in a dictionary that doesn't exist?
It raises a 'KeyError' exception.

34. Can a dictionary have duplicate keys?


No, keys in a dictionary must be unique.

35. What is a class in Python?


A blueprint for creating objects.

36. What is the '__init__()' method used for in a class?


It initializes the attributes of an object when it's created.

37. Define an object in Python.


An instance of a class.

38. How do you access attributes and methods of an object in Python?


By using dot notation: `object_name.attribute` or `object_name.method()`

39. Define database.


A database is a structured collection of data organized for easy access, management,
and manipulation.
40. Define Database Management System (DBMS):
A DBMS is software that facilitates the creation, maintenance, and use of databases.

41. Name a few examples of popular DBMS software.


MySQL, Oracle, PostgreSQL, Microsoft SQL Server.

42. What is a table in a database?


A table is a collection of related data organized in rows and columns.

43. What is a primary key in a database table?


- It is a unique identifier for each record in a table.

44. What is the purpose of the SELECT statement in SQL?


- The SELECT statement retrieves data from a database.

45. How do you retrieve specific columns from a table in SQL?


By specifying the column names after the SELECT keyword: `SELECT column1,
column2 FROM table_name;`

46. What is the purpose of the WHERE clause in SQL?


The WHERE clause filters records based on specified conditions in a SQL query.

47. How do you filter data using the WHERE clause?


By adding conditions after the WHERE keyword: `SELECT * FROM table_name
WHERE condition;`

48.Explain the usage of the ORDER BY clause in SQL.


The ORDER BY clause is used to sort the results of a query in ascending or
descending order based on specified columns.

49. How do you sort data in descending order in SQL?


By adding DESC after the column name in the ORDER BY clause: `SELECT * FROM
table_name ORDER BY column_name DESC;`

50. Explain the purpose of the INSERT statement in SQL.


The INSERT statement is used to add new records to a table.

51. How do you insert specific values into a table using SQL?
- By specifying the column names and their respective values in the INSERT
statement: `INSERT INTO table_name (column1, column2) VALUES (value1, value2);`

52. What is the function of the UPDATE statement in SQL?


The UPDATE statement modifies existing records in a table.

53. How do you update specific records in a table using SQL?


By using the UPDATE statement with the SET keyword to specify the columns to be
updated and their new values: `UPDATE table_name SET column1 = value1, column2
= value2 WHERE condition;`

54. Explain the purpose of the DELETE statement in SQL.


The DELETE statement is used to remove records from a table.

55. How do you delete specific records from a table using SQL?
By using the DELETE statement with the WHERE clause to specify the conditions for
deleting records: `DELETE FROM table_name WHERE condition;`

56. What is the purpose of the DISTINCT keyword in SQL?


- The DISTINCT keyword is used to retrieve unique values from a specified column in
a table.

57. Provide an example of using the DISTINCT keyword in SQL.


`SELECT DISTINCT column_name FROM table_name;`

58. Explain the usage of the GROUP BY clause in SQL.


- The GROUP BY clause is used to group rows that have the same values in specified
columns and perform aggregate functions on them.

59. How do you use the GROUP BY clause with aggregate functions?
By combining the GROUP BY clause with functions like COUNT(), SUM(), AVG(), etc.,
to perform calculations on grouped data.

60. What is the purpose of the HAVING clause in SQL?


- The HAVING clause filters records returned by a GROUP BY clause based on
specified conditions.
61. Explain the concept of JOINS in SQL.
- JOINS are used to combine rows from multiple tables based on a related column
between them.
62. What is a line chart in Pyplot?
A line chart in Pyplot is a type of plot used to visualize data points connected by
straight line segments, commonly used to show trends over time or continuous data.

63. How do you create a line chart using Pyplot in Python?


By using the `plt.plot()` function, passing the x-axis and y-axis data as arguments.

64. Explain the purpose of the `plt.xlabel()` and `plt.ylabel()` functions in Pyplot.
plt.xlabel()` and `plt.ylabel()` are used to label the x-axis and y-axis of the plot,
respectively.

65. What is a bar chart in Pyplot?


A bar chart is a plot that represents categorical data with rectangular bars, where the
length or height of each bar corresponds to the value it represents.

66. How do you create a bar chart using Pyplot in Python?


By using the `plt.bar()` function, specifying the categorical variables and their
corresponding values.

67. Explain the usage of the `plt.title()` function in Pyplot.


`plt.title()` is used to add a title to the plot, providing a brief description or name for the
chart.

68. What is a pie chart in Pyplot?


A pie chart is a circular statistical graphic divided into slices to illustrate numerical
proportions, where the size of each slice represents the proportion of each category.

69. How do you create a pie chart using Pyplot in Python?


- By using the `plt.pie()` function, passing the values for each category and specifying
additional parameters like labels and colors.

70. Explain the purpose of the `plt.legend()` function in Pyplot.


`plt.legend()` is used to add a legend to the plot, displaying labels associated with
different elements of the chart, like different categories in a pie chart.

You might also like