Python variables

Introduction to Variables and Data Types in Python


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:

  1. Integer (int)
  2. Floating point (float)
  3. String (str)
  4. List (list)
  5. Tuple (tuple)
  6. 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"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: