Victor A

2 min read

Python Test nr.1

CodingTestspython

Python Beginners Test

Time Elapsed: 0 seconds

1. What is the output of the following code?

```python
    print(2 * 3 + 4)

    <label><input type="radio" name="q1" value="a"> a) 10</label><br>
    <label><input type="radio" name="q1" value="b"> b) 14</label><br>
    <label><input type="radio" name="q1" value="c"> c) 12</label><br>
    <label><input type="radio" name="q1" value="d"> d) 8</label><br>
</div>

<div class="question">
    <h3>2. Which of the following data types is immutable in Python?</h3>
    <label><input type="radio" name="q2" value="a"> a) List</label><br>
    <label><input type="radio" name="q2" value="b"> b) Dictionary</label><br>
    <label><input type="radio" name="q2" value="c"> c) Set</label><br>
    <label><input type="radio" name="q2" value="d"> d) Tuple</label><br>
</div>

<div class="question">
    <h3>3. What is the correct syntax to create a function in Python?</h3>
    <label><input type="radio" name="q3" value="a"> a) def myFunction:</label><br>
    <label><input type="radio" name="q3" value="b"> function myFunction():</label><br>
    <label><input type="radio" name="q3" value="c"> def myFunction():</label><br>
    <label><input type="radio" name="q3" value="d"> function myFunction:</label><br>
</div>

<div class="question">
    <h3>4. What will be the output of the following code?</h3>

    ```python
        x = 5
        y = 10
        print(x == y)
<label><input type="radio" name="q4" value="a"> a) True</label><br>
<label><input type="radio" name="q4" value="b"> b) False</label><br>
<label><input type="radio" name="q4" value="c"> c) x</label><br>
<label><input type="radio" name="q4" value="d"> d) y</label><br>

5. How do you create a list in Python with the elements 1, 2, and 3?

6. Explain the difference between append() and extend() methods in a list.

7. Write a Python expression to check if the string "hello" contains the substring "ell".

8. What is the purpose of the self keyword in a class definition?