- Is Python compiled or interpreted?
- Python is an interpreted language: the interpreter runs the program line by line (it first turns it into bytecode internally).
- What is the difference between a list and a tuple?
- A list is mutable (it can be changed after creation) and uses [ ]; a tuple is immutable and uses ( ).
- What is the difference between = and ==?
- = assigns a value to a variable; == compares two values and gives True or False.
- What is the difference between / and //?
- / is true division and always gives a float (7/2 = 3.5); // is floor division (7//2 = 3).
- What are mutable and immutable types? Give examples.
- Mutable objects can be changed in place: list, dictionary, set. Immutable objects cannot: int, float, string, tuple.
- What is a dictionary?
- A collection of key : value pairs written in { }. Values are looked up by key, not by position. Keys must be unique and immutable; values can be anything.
- What does len() return for a string?
- The number of characters in it, including spaces.
- What is the difference between break and continue?
- break ends the loop completely; continue skips the rest of the current pass and goes to the next one.
- What is slicing?
- Taking a part of a sequence with [start:stop:step]; stop is not included. 'PYTHON'[1:4] is 'YTH'.
- What is the difference between append() and extend()?
- append() adds its argument as ONE item; extend() adds each item of an iterable separately.
- What is a function? Why do we use functions?
- A named block of code that does one job and can be called many times. Functions avoid repetition and make programs easier to read and test.
- What is the difference between a parameter and an argument?
- A parameter is the name in the function definition; an argument is the actual value passed when the function is called.
- What are default arguments?
- Parameters that have a value in the definition, used when the caller does not pass one. They must come after the parameters without defaults.
- What is the difference between local and global variables?
- A local variable is created inside a function and exists only there; a global variable is created outside all functions and can be read anywhere. To change a global inside a function, declare it with the global keyword.
- What does a function return if it has no return statement?
- None.
- Can a function return more than one value?
- Yes — it returns them as a tuple, e.g. return a, b.