1. Integer Variable
# An integer variable to store the number of students in a class
number_of_students = 30
print("Number of students:", number_of_students)
Explanation: Here, we create an integer variable number_of_students
to hold the value 30
. We then print the value.
2. Float Variable
# A float variable to store the average score of students
average_score = 85.5
print("Average score:", average_score)
Explanation: This variable average_score
is a float that holds a decimal value representing the average score.
3. String Variable
# A string variable to hold the name of the course
course_name = "Introduction to Python"
print("Course Name:", course_name)
Explanation: The variable course_name
is a string that contains the name of the course.
4. Boolean Variable
# A boolean variable to indicate whether the class is active
is_class_active = True
print("Is the class active?", is_class_active)
Explanation: The is_class_active
variable is a boolean that indicates whether the class is currently active or not.
5. List Variable
# A list variable to store the names of students
students = ["Alice", "Bob", "Charlie"]
print("Students in the class:", students)
Explanation: We create a list variable called students
to store multiple names.
6. Tuple Variable
# A tuple variable to store coordinates (x, y)
coordinates = (10, 20)
print("Coordinates:", coordinates)
Explanation: The variable coordinates
is a tuple containing two integer values representing x and y coordinates.
7. Dictionary Variable
# A dictionary variable to store student grades
student_grades = {
"Alice": 90,
"Bob": 80,
"Charlie": 85
}
print("Student Grades:", student_grades)
Explanation: The variable student_grades
is a dictionary mapping student names to their grades.
8. Set Variable
# A set variable to store unique subjects taken by students
subjects = {"Math", "Science", "English"}
print("Subjects offered:", subjects)
Explanation: The variable subjects
is a set that contains unique subject names.
9. None Variable
# A variable that can hold no value
student_grade = None
print("Student Grade:", student_grade)
Explanation: The variable student_grade
is initialized to None
, indicating that it currently has no value.
10. Complex Number Variable
# A complex number variable representing a point in the complex plane
complex_number = 3 + 4j
print("Complex Number:", complex_number)
Explanation: The complex_number
variable holds a complex number, where j
is the imaginary unit.