
Data Types and Variables
1. Write a Python program to print the type of the following variables: a = 5, b =
5.0, c = "Hello".
2. Create a variable x and assign it the value 10. Print the value of x.
3. Swap the values of two variables a = 5 and b = 10 without using a third variable.
4. Convert the integer 123 to a string and print its type.
5. Convert the string "3.14" to a float and print its type.
6. Create a variable name and assign it your name. Print the value of name.
7. Create a variable age and assign it your age. Print the value of age.
8. Create a variable is_student and assign it a boolean value (True or False). Print
the value of is_student.
9. Create a variable pi and assign it the value 3.14159. Print the value of pi.
10. Create a variable complex_num and assign it the value 2 + 3j. Print the value of
complex_num.
Strings
11. Create a string s = "Hello, World!" and print its length.
12. Print the first character of the string s = "Python".
13. Print the last character of the string s = "Programming".
14. Print the substring "World" from the string s = "Hello, World!".
15. Convert the string s = "hello" to uppercase and print the result.
16. Convert the string s = "HELLO" to lowercase and print the result.
17. Replace the word "World" with "Python" in the string s = "Hello, World!".
18. Check if the string s = "Python" starts with the letter "P".
19. Check if the string s = "Python" ends with the letter "n".
20. Split the string s = "Hello, World!" into a list of words using the comma as a
delimiter.
Python Syntax
21. Write a Python program to print "Hello, World!".
22. Write a Python program to print your name and age on separate lines.
23. Write a Python program to print the sum of two numbers 5 and 10.
24. Write a Python program to print the product of two numbers 3 and 7.
25. Write a Python program to print the result of 2 ** 3 (2 raised to the power of 3).