What is a variable in programming?
A variable is a container used to store data values.
Example in Python:
python
Copy
Edit
name = “David”
age = 25
What are the basic data types in Python?
int: Integer (10)
float: Decimal number (3.14)
str: String (“Hello”)
bool: Boolean (True or False)
Example:
python
Copy
Edit
price = 19.99 # float
is_paid = False # bool
username = “Alex” # str
What is a function and why is it used?
A function is a block of reusable code that performs a specific task.
Example:
python
Copy
Edit
def greet(name):
print(f”Hello, {name}!”)
greet(“David”)
What are the types of functions in Python?
Built-in functions: print(), len(), range()
User-defined functions: You create them with def
Example:
python
Copy
Edit
def add(x, y):
return x + y
What is a conditional statement?
It is used to perform different actions based on different conditions using if, elif, and else.
Example:
python
Copy
Edit
age = 20
if age >= 18:
print(“Adult”)
else:
print(“Minor”)
What is a for loop?
A for loop repeats code a certain number of times.
Example:
python
Copy
Edit
for i in range(5):
print(i)
Output: 0 1 2 3 4
What is a while loop?
A while loop repeats code as long as a condition is true.
Example:
python
Copy
Edit
count = 0
while count < 3:
print(“Hi”)
count += 1
What is the difference between mutable and immutable types?
Mutable: Can be changed (e.g., lists)
Immutable: Cannot be changed (e.g., strings, tuples)
Example:
How do you convert between data types?
A4:
Use built-in functions like int(), float(), str()
Example:
python
Copy
Edit
price = “100”
converted = int(price)
What is the difference between a parameter and an argument?
arameter is a variable in a function definition.
Argument is the actual value passed to the function.
Example:
python
Copy
Edit
def add(x, y): # x and y are parameters
return x + y
add(3, 5) # 3 and 5 are arguments
What is a return statement and how is it used?
The return statement ends a function and optionally sends back a value.
Example:
python
Copy
Edit
def square(n):
return n * n
result = square(4) # returns 16
What is a default parameter value?
t allows a function to use a default value if no argument is passed.
Example:
python
Copy
Edit
def greet(name=”Guest”):
return f”Welcome, {name}!”
print(greet()) # Output: Welcome, Guest!
print(greet(“Alice”)) # Output: Welcome, Alice!
What are keyword arguments?
hey allow you to call a function using parameter names explicitly.
Keyword arguments (or named arguments) are values that, when passed into a function, are identifiable by specific parameter names. A keyword argument is preceded by a parameter and the assignment operator, = .
What is a variable-length argument (*args, **kwargs)?
A6:
*args allows multiple positional arguments.
**kwargs allows multiple keyword arguments.
Example:
python
Copy
Edit
def print_args(*args):
for arg in args:
print(arg)
def print_kwargs(**kwargs):
for key, value in kwargs.items():
print(f”{key}: {value}”)
print_args(1, 2, 3)
print_kwargs(name=”David”, age=25)
What is a lambda function?
A lambda is a small anonymous function using the lambda keyword. Best for short, one-liner functions.
Syntax:
python
Copy
Edit
lambda arguments: expression
Example:
python
Copy
Edit
square = lambda x: x * x
print(square(5)) # Output: 25
Can a function return multiple values?
Yes, it can return multiple values as a tuple.
Example:
python
Copy
Edit
def get_min_max(numbers):
return min(numbers), max(numbers)
low, high = get_min_max([1, 3, 9])
print(low, high) # Output: 1 9
What is recursion?
technique where a function calls itself to solve smaller instances of a problem.
Example:
python
Copy
Edit
def factorial(n):
if n == 1:
return 1
return n * factorial(n - 1)
print(factorial(5)) # Output: 120
What are some real-world uses of functions?
A10:
User input processing
Data transformation
Web requests handling
Repeated tasks like calculations or string formatting
Example in Web App:
python
Copy
Edit
def calculate_total(cart_items):
return sum(cart_items)
What is web Development?
Web development refers to the overall process of creating websites or web applications, including the project’s design, layout, coding, content creation, and functionality. It involves using a combination of programming languages, tools, and frameworks to bring a website or web application to life.
Define and expalin the two sectors of web development?
Front-End (Client-Side): What users interact with directly in the browser. This includes HTML, CSS, and JavaScript.
Back-End (Server-Side): Handles server logic, database interactions, and application functionality. This is typically managed using server-side languages like Python, or PHP.
What is a frontend(Client side)
Front-end development involves the “client-facing” side of web development. That is to say usually, front-end web development refers to the portion of the site, app, or digital product that users will see and interact with. A Front-End Developer, therefore, is responsible for the way a digital product looks and “feels,” which is why they are often also referred to as Web Designers.
What is a full stack Developer?
A Full-Stack Developer is someone familiar with both front- and back-end development. Full Stack Developers usually understand a wide variety of programming languages and because of their versatility, they might be given more of a leadership role on projects than developers who specialize. They are generalists, adept at wearing both hats, and familiar with every layer of development. Obviously, employers want to hire Full-Stack Developers – according to an Indeed study, they are the fourth-most in-demand job in tech.
Define and state the stages involve in web development.
Planning: Understanding the project requirements and goals.
Design: Creating wireframes and mockups to visualize the layout and user experience.
Development: Writing code to build the website or application.
Testing: Ensuring the website works correctly across different browsers and devices.
Deployment: Making the website live on the internet.
Maintenance: Updating and improving the website over time.
What are backend Developers
if Front-End Developers are responsible for how a digital product looks, Back-End Developers are focused on how it works. A Back-End Developer creates the basic framework of a website before maintaining it and ensuring it performs the way it should, including database interactions, user authentication, server, network and hosting configuration, and business logic. Working behind the scenes – or server-side – Back End Developers are concerned with the systems and structures that allow computer applications to perform as desired.