Python Fundamentals:

  1. Question: What is Python? Mention some key features.
    Answer: Python is a high-level, interpreted programming language known for its simplicity and readability. Key features include dynamic typing, automatic memory management, and a large standard library.
  2. Question: How do you write comments in Python?
    Answer: Comments in Python are written using the # symbol. They are ignored by the interpreter and are used to provide explanations or notes in the code.

Lists and Tuples:

  1. Question: What is the difference between a list and a tuple in Python?
    Answer: Lists are mutable, meaning their elements can be modified, added, or removed after creation. Tuples are immutable, meaning their elements cannot be changed after creation.
  2. Question: How do you access elements in a list and a tuple?
    Answer: Elements in both lists and tuples are accessed using indexing. For example, my_list[2] accesses the third element in my_list.

Strings:

  1. Question: How do you concatenate two strings in Python?
    Answer: Strings can be concatenated using the + operator, like this: "Hello, " + "world!".
  2. Question: What is string slicing?
    Answer: String slicing involves extracting a portion of a string by specifying start and end indices. For example, "Python"[1:4] would give "yth".

List Methods:

  1. Question: Explain the append() method in Python lists.
    Answer: The append() method is used to add an element to the end of a list.
  2. Question: How does the remove() method work in Python lists?
    Answer: The remove() method removes the first occurrence of a specified element from the list.

Dictionaries:

  1. Question: What is a dictionary in Python?
    Answer: A dictionary is an unordered collection that stores data as key-value pairs. Keys must be unique and immutable.
  2. Question: How do you access the value associated with a specific key in a dictionary?
    Answer: You can access the value using the key in square brackets, like this: my_dict["key"].

Control Flow (If-Else, For, While):

  1. Question: What is the purpose of the if statement in Python?
    Answer: The if statement is used for conditional execution of code. It allows you to run specific code blocks if a certain condition is true.
  2. Question: Explain the for loop in Python.
    Answer: The for loop is used to iterate over a sequence (like a list, tuple, or string) and execute a block of code for each item in the sequence.
  3. Question: How does the while loop differ from the for loop?
    Answer: The for loop is used to iterate over a sequence, while the while loop repeatedly executes a block of code as long as a specified condition is true.
error: Content is protected !!