0% found this document useful (0 votes)
3 views3 pages

Python Assignment Solution

The document provides definitions and examples for key Python concepts such as variables, data types, identifiers, and tuples. It outlines the differences between lists and tuples, lists five built-in data types with examples, and includes Python programs demonstrating list and tuple operations. Additionally, it shows how to take multiple inputs from the user and store them in a list.

Uploaded by

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

Python Assignment Solution

The document provides definitions and examples for key Python concepts such as variables, data types, identifiers, and tuples. It outlines the differences between lists and tuples, lists five built-in data types with examples, and includes Python programs demonstrating list and tuple operations. Additionally, it shows how to take multiple inputs from the user and store them in a list.

Uploaded by

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

Python Assignment Solutions

1. Define the following terms with examples

a) Variable:

A variable is a name given to a memory location to store data.

Example:

x = 10

name = "Alice"

b) Data type:

It specifies the kind of value a variable holds.

Example:

age = 20 (Integer)

pi = 3.14 (Float)

c) Identifier:

It is the name used to identify variables, functions, classes, etc.

Example: student_name = "John"

d) Tuple:

Tuple is an immutable, ordered collection of items.

Example:

student = ("Asha", 20, "Biology")

2. Difference between List and Tuple (7 differences)

List:

- Mutable

- Uses []

- Slower than tuple

- Can add/remove elements


Python Assignment Solutions

- Uses more memory

- Suitable for dynamic data

- Example: [1, 2, 3]

Tuple:

- Immutable

- Uses ()

- Faster than list

- Cannot add/remove

- Uses less memory

- Suitable for fixed data

- Example: (1, 2, 3)

3. Five built-in data types in Python with examples

int -> num = 100

float -> pi = 3.14

str -> name = "Alice"

list -> marks = [90, 80, 70]

tuple -> student = ("John", 20)

4. Python program with list operations

marks = [85, 78, 92, 88, 76]

# a) 3rd subject

print("3rd subject marks:", marks[2])

# b) Replace 2nd

marks[1] = 80
Python Assignment Solutions

# c) Add two

marks.append(90)

marks.append(95)

# d) Sort

marks.sort()

print("Sorted marks:", marks)

5. Tuple operations

info = ("Asha", 20, "Biology")

# a) Name & subject

print(info[0], info[2])

# b) Modify age

info[1] = 21

Error: TypeError: 'tuple' object does not support item assignment

6. Python program to take 3 inputs

data = []

for i in range(3):

value = input("Enter value: ")

data.append(value)

print("The list is:", data)

You might also like