Exercise:
Exercise: Declare two variables, one integer and one string, and print them on separate lines.
In this lesson, we will be covering the basics of variables and data types in Python. Understanding these concepts is fundamental to writing any program in any programming language. In Python, variables are used to store values that can be used later in the program. These values can be of different data types such as integers, strings, lists, and dictionaries.
Python has several built-in data types, which include:
- Integer (int)
- Floating point (float)
- String (str)
- List (list)
- Tuple (tuple)
- Dictionary (dict)
In this lesson, we will be focusing on the first three data types: int, float, and str.
Example 1: Declaring and using an integer variable in Python:
x = 10
print(x) # Output: 10
Example 2: Declaring and using a floating point variable in Python:
y = 10.5
print(y) # Output: 10.5
Example 3: Declaring and using a string variable in Python:
name = "John Doe"
print(name) # Output: John Doe
This is just an introduction to variables and data types in Python. In future lessons, we will explore these concepts in more detail and see how we can use them to build more complex programs.
Exercise Solution:
age = 30
full_name = "Jane Doe"
print(age)
print(full_name)
Leave a Reply