Assignment -1 python
1. Who created Python?
Guido van Rossum.
2. When was Python 1.0 released?
1991.
3. What inspired the name “Python”?
The comedy show Monty Python’s Flying Circus.
4. Which Python version introduced Unicode support?
Python 2.0.
5. Is Python interpreted or compiled?
Interpreted.
6. What does “dynamically typed” mean?
Variables do not need type declarations.
7. Give an example of a simple Python loop .
for i in range(5):
print(i)
8. What is the output of the above loop?
01234
9. Which function is used to take input from the user?
input()
10. What is the type of value returned by input()?
String.
11. How do you convert input to an integer?
int(input())
12. Give an example of a Python comment.
# This is a comment
13. Which symbol is used to start a block in Python?
Colon :.
14. What is indentation used for?
Defining code blocks.
15. Give an example of a function definition .
def greet():
print("Hello!")
16. What is the output of print("Hello", "Python", sep="")?
HelloPython
17. What does \n represent?
New line.
18. What does \t represent?
Tab space.
19. Give an example of a string expression .
print("Python" * 3)
20. What is the output of "Python" * 3?
PythonPythonPython
21. Which operator is used for exponentiation?
**
22. What is the output of 10 + 2 * 3?
16 (due to precedence)
23. Give an example of a relational expression.
x < y
24. Give an example of a logical expression.
(a > b) and (b > 0)
25. What is the output of print("A","B","C",sep="-")?
A-B-C
26. Which function prints formatted output using f-strings?
print(f"{name} version is {version}")
27. Give an example of a list .
[1, 2, 3, "apple"]
28. Give an example of a dictionary .
{"name": "Alice", "age": 25}
29. What is the output of print("Hello", end=" ") followed by print("World")?
Hello World
30. Which escape sequence prints a backslash?
\\
1. Explain the history and evolution of Python from 1989
to the present.
Python was created by Guido van Rossum at CWI in the late 1980s. Python 1.0 (1991)
introduced functions, exceptions, and core data types. Python 2.0 (2000) added list
comprehensions, garbage collection, and Unicode support. Python 3.0 (2008) introduced
cleaner syntax, better Unicode handling, and removed legacy issues. Today Python is
maintained by PSF and dominates AI, ML, data science, and automation.
2. Describe the key features of Python
Python has simple syntax, is interpreted, dynamically typed, supports OOP and procedural
programming, and includes a large standard library. Example:
for i in range(5):
print(i)
It also supports cross-platform execution and has strong community support.
3. Explain the steps to install Python on Windows
Steps include downloading Python from [Link], running the installer, checking “Add
Python to PATH,” installing pip and IDLE, and verifying installation using python --
version. Optional IDE installation includes VS Code or PyCharm.
4. Describe how to set up a Python development
environment.
Steps include installing Python, installing an IDE, adding extensions (Python, Jupyter),
creating a project folder, creating a virtual environment (python -m venv env), installing
packages (pip install pandas numpy), and running a test program like:
print("Python environment is ready!")
5. Explain basic syntax rules with examples.
Python is case-sensitive, uses indentation instead of braces, uses # for comments, and does
not require variable declarations. Example:
if 5 > 2:
print("Five is greater")
6. Describe data types with examples
Python supports numeric types (int, float, complex), sequences (list, tuple, range),
mapping (dict), sets (set, frozenset), boolean, NoneType, and binary types (bytes,
bytearray). Example:
list_val = [1, 2, 3, "apple"]
7. Explain mutable and immutable data types with
examples.
Mutable: list, dict, set, bytearray.
Immutable: int, float, str, tuple, frozenset.
Example:
list_val = [1,2,3] is mutable;
tuple_val = (10,20) is immutable.
8. Explain variables and assignment statements with
examples.
Variables store values in memory. Python allows multiple assignments:
a, b, c = 1, 2, 3
x = y = z = 100
Variable names must follow rules (no starting with digits, no special characters).
9. Describe different types of expressions
Arithmetic, relational, logical, string, membership, identity, and bitwise expressions.
Example:
print("Arithmetic:", a + b, a - b)
print("Logical:", (a > b) and (b > 0))
10. Explain operator precedence with an example.
Python evaluates expressions using precedence rules: parentheses → exponent →
multiplication/division → addition/subtraction → comparison → logical.
Example: 10 + 2 * 3 = 16.
11. Explain input operations
input() reads user input as a string. Conversion uses int() or float().
Example:
age = int(input("Enter your age: "))
Multiple inputs use split() or map().
12. Explain output operations using print(), sep, end, and
escape sequences.
Examples:
print("A","B","C",sep="-")
print("Hello", end=" ")
print("World")
Escape sequences include \n, \t, \\, \".
13. Explain formatted output using f-strings and format().
print(f"{name} version is {version}")
print("Name: {}, Age: {}".format("John", 25))
14. Explain the use of raw strings with an example.
Raw strings ignore escape sequences.
Example:
print(r"C:\newfolder\test")
15. Describe the program that demonstrates all Python
data types.
The program defines variables of types int, float, complex, str, list, tuple, range, dict, set,
frozenset, bool, bytes, bytearray, and memoryview, then prints each with its type.
16. Explain the expressions_demo() program.
The program demonstrates arithmetic, relational, logical, assignment, bitwise, membership,
and identity expressions using variables a, b, lists, and prints results.
17. Explain escape codes with examples
The program demonstrates \n, \t, \", \', \\, \r, \a, Unicode (\u2764), octal (\101), and
hex (\x41) escape sequences.
18. Explain conditional statements with example
age = 18
if age >= 18:
print("Adult")
else:
print("Minor")
Conditions allow decision-making in programs.
19. Explain loops in Python
For loop:
for i in range(5):
print(i)
While loop:
count = 1
while count <= 5:
print(count)
count += 1
20. Explain functions in Python with examples.
Functions are defined using def.
Example:
def greet():
print("Hello!")
Functions must be defined before calling.