Python - Set 4

Python Question & Answer Practice

Python Practice – Questions & Answers

Beginner Level

Q46. For loop.
for i in range(5):
    print(i)
Q47. While loop.
while x < 5:
    x += 1
Q48. Function definition.
def greet():
    print("Hello")
Q49. Return value from function.
def add(a,b):
    return a+b
Q50. Check data type.
type(x)

Intermediate Level

Q51. Import module.
import math
Q52. Random number.
import random
random.randint(1,10)
Q53. Date and time.
import datetime
datetime.datetime.now()
Q54. Virtual environment.

Isolated Python environment.

Q55. pip.

Python package manager.

Advanced Level

Q56. Custom exception.
class MyError(Exception):
    pass
Q57. JSON in Python.
import json
json.dumps(data)
Q58. API request.
import requests
requests.get(url)
Q59. Unit testing.

Test code functionality.

Q60. Python best practices.

Readable code, PEP8, modular design.

No comments:

Post a Comment