Understanding Strings, Integers, and Floats
In this tutorial, you'll learn about strings, integers, and floats—the three most common types of data in Python. By the end of this lesson, you'll know how to use them in programs and when to use each type.


1. What Are Strings, Integers, and Floats?

Strings (str)

Integers (int)

Floats (float)


2. How to Use Strings, Integers, and Floats in Python

a. Strings

You can use strings to store and manipulate text.
Example:

name = "Alice"

print("Hello, my name is", name)


Output:

Hello, my name is Alice


You can also combine strings using the + operator:

greeting = "Good"

time = "morning"

print(greeting + " " + time)


Output:

Good morning


b. Integers

You can use integers for math and counting.
Example:

age = 12

print("I am", age, "years old.")


Output:

I am 12 years old.


You can perform math operations:

apples = 5

oranges = 3

total = apples + oranges

print("Total fruits:", total)


Output:

Total fruits: 8


c. Floats

Use floats for numbers with decimals.
Example:

price = 3.99

print("The price is", price)


Output:

The price is 3.99


You can also do math with floats:

radius = 2.5

area = 3.14 * (radius ** 2)

print("The area of the circle is:", area)


Output:

The area of the circle is: 19.625



3. Combining Strings, Integers, and Floats

You can mix strings, integers, and floats in one program.
Example:

item = "notebook"

quantity = 3

price_per_item = 1.5

total_price = quantity * price_per_item

print("You bought", quantity, item + "(s) for a total of $", total_price)


Output:

You bought 3 notebook(s) for a total of $ 4.5



4. Practice Exercises

Exercise 1: String Practice

Create a program that:

Exercise 2: Integer Practice

Write a program that:

Exercise 3: Float Practice

Write a program that:

Exercise 4: Combining Data Types

Write a program that:



5. Bonus Challenge

Write a program that calculates the total cost of a shopping list:

     The total cost is $4.0.


6. What’s Next?

Once you’re comfortable using strings, integers, and floats, you can explore more complex data types like lists and dictionaries. Great work getting started with Python! 🎉