Kritim Yantra
Jul 14, 2025
Answer:
Python is a high-level, interpreted, and general-purpose programming language known for its simple syntax, readability, and wide usage in web development, data science, AI, automation, and more.
Answer:
Feature | List | Tuple |
---|---|---|
Mutable | โ Yes | โ No |
Syntax | [] |
() |
Use case | Dynamic data | Fixed data |
Answer:
# This is a single-line comment
For multi-line comments, use triple quotes (although it's technically a string):
"""
This is
a multi-line comment
"""
Answer:
Variables are containers for storing data. Python uses dynamic typing, so you donโt need to declare the type.
name = "Alice"
age = 25
name = input("Enter your name: ")
input()
always returns a string, so convert it if needed:
age = int(input("Enter age: "))
Answer:
A function is a block of reusable code.
def greet(name):
return f"Hello, {name}"
Answer:
int
, float
, complex
str
bool
list
, tuple
, set
, dict
NoneType
==
and is
?==
checks value equalityis
checks object identity (same memory)a = [1]
b = [1]
print(a == b) # True
print(a is b) # False
Answer:
Python uses indentation (typically 4 spaces) to define blocks of code. No curly braces {}
.
if True:
print("Yes") # Must be indented!
person = {"name": "Alice", "age": 30}
A dict is a collection of key-value pairs.
for i in range(5):
print(i)
while i < 5:
print(i)
i += 1
and
or
not
if x > 0 and x < 10:
print("Between 1 and 9")
break
, continue
, and pass
?break
: Exits the loopcontinue
: Skips to next iterationpass
: Does nothing (placeholder)Answer:
A module is a .py file containing Python definitions and code. You import it using:
import math
append()
and extend()
?a = [1, 2]
a.append([3, 4]) # [1, 2, [3, 4]]
a.extend([3, 4]) # [1, 2, 3, 4]
Answer:
An anonymous, one-line function.
square = lambda x: x * x
print(square(5)) # 25
squares = [x*x for x in range(5)]
Concise way to generate a list.
def func(*args, **kwargs):
print(args)
print(kwargs)
*args
= variable positional arguments**kwargs
= variable keyword argumentstry:
x = 1 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
finally:
print("Done")
class Animal:
def __init__(self, name):
self.name = name
Used for object-oriented programming.
Answer:
When a class inherits properties and methods from another class.
class Dog(Animal):
pass
__init__
and self
?__init__
: Constructor methodself
: Refers to the instance calling the methodAnswer:
A package is a directory with an __init__.py
file, used to group related modules.
pip install requests
Answer:
An isolated Python environment to manage dependencies for a specific project.
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
with open('file.txt', 'r') as f:
content = f.read()
with open('file.txt', 'w') as f:
f.write("Hello")
__name__ == '__main__'
statement?Used to run code only when the script is executed directly, not when imported.
if __name__ == "__main__":
main()
Answer:
PEP8 is Python's official style guide for writing readable and consistent code (e.g., indentation, line length, naming conventions).
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google