0% found this document useful (0 votes)
4 views

assignment

Php assignment questions with answers

Uploaded by

sahil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

assignment

Php assignment questions with answers

Uploaded by

sahil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

2 Marks Questions

Q1. Why tuples are called as immutable?

Tuples are immutable because once a tuple is created, its elements cannot
be changed, added, or removed. This behavior ensures that the data In
tuples remains constant throughout the program.

**Q2. Mention the use of //, , % operator in Python.

//: Floor division operator, returns the largest integer less than or equal to the
division result.

Example: 7 // 2 = 3.

**: Exponentiation operator, raises a number to the power of another.

Example: 2 ** 3 = 8.

%: Modulus operator, returns the remainder of division.

Example: 7 % 2 = 1.

Q3. Explain variable in Python with its rules and conventions for declaration.

A variable in Python is a named location in memory used to store data.

Rules and Conventions:

Variable names must start with a letter or underscore (_).

Cannot start with a number or use special characters.


Variable names are case-sensitive.

Use meaningful names (e.g., age, salary).

Q4. Enlist applications for Python programming.

Web development (e.g., Django, Flask).

Data analysis and visualization (e.g., Pandas, Matplotlib).

Artificial Intelligence and Machine Learning.

Scientific computing.

Scripting and automation.

Game development.

Q5. Describe Python Interpreter.

A Python Interpreter is a program that reads and executes Python code. It


converts high-level Python code into machine-readable format (bytecode)
and executes it line by line.

Q6. Explain any 4 features of Python programming.


Python is a versatile and powerful programming language known for its
simplicity and readability. Below are four key features of Python:

1. Easy to Learn and Use:

Python has a simple and straightforward syntax that closely resembles the
English language. This makes it easy for beginners to learn and write Python
programs. For example:

Print(“Hello, World!”)

This program prints a message to the screen with minimal complexity.

2. Interpreted Language:

Python is an interpreted language, meaning that the code is executed line by


line at runtime without needing prior compilation. This helps in debugging
and testing code more efficiently.

Example:

X = 10

Y=5

Print(x + y)

The interpreter executes these statements sequentially.

3. Portability:
Python is platform-independent, which means a Python program written on
one operating system (e.g., Windows) can run on another (e.g., Linux,
macOS) without modification. This portability makes Python highly versatile
for cross-platform applications.

4. Extensive Library Support:

Python provides a rich set of libraries and modules that can be imported to
simplify tasks. For example:

NumPy for numerical computing.

Matplotlib for data visualization.

Flask/Django for web development.

These libraries eliminate the need to write complex code from scratch.

Q7. List and explain different data types used in Python.

Python supports a variety of data types, each suited for different use cases.
Below is a list and explanation of commonly used data types:
1. Int (Integer):

Represents whole numbers, both positive and negative.

Example:

X = 10

Y = -5

Print(type(x)) # Output: <class ‘int’>

2. Float (Floating Point):

Represents decimal numbers.

Example:

Pi = 3.14

Print(type(pi)) # Output: <class ‘float’>

3. Str (String):

Represents a sequence of characters enclosed in quotes. Strings can be


manipulated using various methods like slicing, concatenation, etc.

Example:

Name = “Python”

Print(name.upper()) # Output: PYTHON

4. List:
Represents an ordered collection of items, which can be of different types.
Lists are mutable, meaning their elements can be modified.

Example:

Numbers = [1, 2, 3, 4]

Numbers.append(5)

Print(numbers) # Output: [1, 2, 3, 4, 5]

5. Tuple:

Similar to lists but immutable. Useful when data should not be modified.

Example:

Coordinates = (10, 20)

Print(coordinates[0]) # Output: 10

6. Dict (Dictionary):

Represents key-value pairs for quick data retrieval.

Example:

Student = {“name”: “Alice”, “age”: 20}

Print(student[“name”]) # Output: Alice

You might also like