$ git add .
$ git commit -m "write some message"
$ git push
This repository has been created for Python Training at Instill Learning.
- Text Type: str
- Numeric Types: int, float, complex
- Sequence Type: list, tuple, range
- Mapping Type: dict
- Set Type: set, frozenset
- Boolean Type: bool
- Binary Type: bytes, bytearray, memoryview
- None Type: NoneType
type(variable)
- List: a collection which is ordered and changable also allows duplicate items.
- Tuple: a collection which is ordered and unchangable also allows duplicate items.
- Set: a collection which is unordered and unchangable also not allow duplicate items.
- Dictionary: a collection which is ordered (before python 3.6 it was unordered) and changable also Not allow duplicate items.
### Easy
1. **Which of the following is a valid variable name in Python?**
- A) `1_variable`
- B) `variable_name`
- C) `variable-name`
- D) `None`
2. **What data type is the number `42` in Python?**
- A) `float`
- B) `str`
- C) `int`
- D) `bool`
3. **Which of the following is used to represent a string in Python?**
- A) `{}`
- B) `()`
- C) `""`
- D) `[]`
4. **What will be the data type of `x` after the following assignment: `x = 3.14`?**
- A) `int`
- B) `str`
- C) `float`
- D) `complex`
5. **Which of the following is the correct way to define a dictionary in Python?**
- A) `my_dict = [key1: 'value1', key2: 'value2']`
- B) `my_dict = (key1: 'value1', key2: 'value2')`
- C) `my_dict = {key1: 'value1', key2: 'value2'}`
- D) `my_dict = "key1: 'value1', key2: 'value2'"`
### Medium
6. **Which of the following statements about Python lists is true?**
- A) Lists are immutable.
- B) Lists can contain elements of different data types.
- C) Lists are defined using parentheses `()`.
- D) A list cannot contain another list.
7. **What will be the result of the following operation: `type( (1, ) )`?**
- A) `int`
- B) `str`
- C) `list`
- D) `tuple`
8. **Which function can convert a string into an integer in Python?**
- A) `int()`
- B) `str()`
- C) `float()`
- D) `bool()`
9. **What is the result of the following expression: `bool("False")`?**
- A) `True`
- B) `False`
- C) `""`
- D) `None`
10. **Which method would you use to add an element to a set in Python?**
- A) `append()`
- B) `add()`
- C) `insert()`
- D) `push()`
### Hard
11. **Which of the following is not a legal variable name in Python?**
- A) `_myvar`
- B) `my_var`
- C) `2myvar`
- D) `myVar`
12. **If `x = 5` and `y = "5"`, what will `type(x+y)` produce?**
- A) `int`
- B) `TypeError`
- C) `str`
- D) `float`
13. **What does the `is` operator test for?**
- A) Value equality
- B) Identity equality
- C) Membership
- D) Size comparison
14. **Which of the following correctly creates a byte data type in Python?**
- A) `b = bytes(5)`
- B) `b = byte[5]`
- C) `b = 5b`
- D) `b = "5".to_bytes()`
15. **In Python, what is the correct way to declare a complex number?**
- A) `c = 1 + j2`
- B) `c = 1 + 2i`
- C) `c = 1 + 2j`
- D) `c = complex(1,2)`
------------------------------------
ANSWERS::
- **1**: B) `variable_name`
- **2**: C) `int`
- **3**: C) `""`
- **4**: C) `float`
- **5**: C) `my_dict = {key1: 'value1', key2: 'value2'}`
- **6**: B) Lists can contain elements of different data types.
- **7**: D) `tuple`
- **8**: A) `int()`
- **9**: A) `True`
- **10**: B) `add()`
- **11**: C) `2myvar`
- **12**: B) `TypeError`
- **13**: B) Identity equality
- **14**: A) `b = bytes(5)`
- **15**: C) `c = 1 + 2j` and D) `c = complex(1,2)`