Python Fundamentals:
- 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. - 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:
- 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. - 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 inmy_list.
Strings:
- Question: How do you concatenate two strings in Python?
Answer: Strings can be concatenated using the+operator, like this:"Hello, " + "world!". - 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:
- Question: Explain the
append()method in Python lists.
Answer: Theappend()method is used to add an element to the end of a list. - Question: How does the
remove()method work in Python lists?
Answer: Theremove()method removes the first occurrence of a specified element from the list.
Dictionaries:
- 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. - 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):
- Question: What is the purpose of the
ifstatement in Python?
Answer: Theifstatement is used for conditional execution of code. It allows you to run specific code blocks if a certain condition is true. - Question: Explain the
forloop in Python.
Answer: Theforloop 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. - Question: How does the
whileloop differ from theforloop?
Answer: Theforloop is used to iterate over a sequence, while thewhileloop repeatedly executes a block of code as long as a specified condition is true.

