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

1.python Variables and Datatypes

The document contains a series of Python coding exercises focused on variables and data types. It includes tasks such as creating variables, swapping values, working with lists, tuples, sets, dictionaries, and other data types. Each exercise is accompanied by sample code and print statements to demonstrate the output.
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)
17 views3 pages

1.python Variables and Datatypes

The document contains a series of Python coding exercises focused on variables and data types. It includes tasks such as creating variables, swapping values, working with lists, tuples, sets, dictionaries, and other data types. Each exercise is accompanied by sample code and print statements to demonstrate the output.
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

PYTHON VARIABLES AND DATA TYPES CODING

PROGRAMS

Q1. Create a variable x with value 10 and print its type.


x = 10
print("Value:", x)
print("Type:", type(x))

Q2. Assign the same value 100 to three variables a, b, and c in


one line.
a = b = c = 100
print(a, b, c)

Q3. Swap the values of two variables without using a third


variable.
x, y = 5, 10
x, y = y, x
print("x =", x, "y =", y)

Q4. Create a list of fruits and print its type and elements.
fruits = ["apple", "banana", "mango"]
print(type(fruits), fruits)

Q5. Create a tuple of 3 numbers and print the second


element.
numbers = (10, 20, 30)
print("Second element:", numbers[1])
Q6. Create a set with duplicate values and print it.
s = {1, 2, 2, 3, 4, 4}
print("Set after removing duplicates:", s)

Q7. Create a dictionary with keys name and age and print them.
person = {"name": "Alice", "age": 25}
print("Name:", person["name"])
print("Age:", person["age"])

Q8. Write a program to check the type of variable id = 1.3.


id = 1.3
print("Value:", id)
print("Type:", type(id))

Q9. Create a range of numbers from 0 to 9 and print them


using a loop.
r = range(10)
for i in r:
print(i, end=" ")

Q10. Create a boolean variable is_active = True and check its


type.
is_active = True
print("Value:", is_active)
print("Type:", type(is_active))
Q11. Reassign a variable salary = 50000, then change it to 55000
and print both values.
salary = 50000
print("Old Salary:", salary)
salary = 55000
print("Updated Salary:", salary)

Q12. Create a complex number z = 2 + 3j and print its real and


imaginary parts.
z = 2 + 3j
print("Real part:", [Link])
print("Imaginary part:", [Link])

Q13. Create a string variable language = "Python" and print its


first and last characters.
language = "Python"
print("First character:", language[0])
print("Last character:", language[-1])

Q14. Check if the identifier my_var is valid and assign a value to


it.
my_var = 123
print("Valid identifier:", my_var)

Q15. Create a frozenset from the list [1, 2, 3, 2, 1] and print it.
fs = frozenset([1, 2, 3, 2, 1])
print("Frozenset:", fs)

You might also like