Python Learning – Day 3: Strings and User Input
Introduction
Welcome to Day 3 of my Python learning journey.
In this lesson, I learned how Python interacts with users using strings and user input.
Most real-world applications need to communicate with users, and this lesson explains how Python takes input, processes it, and displays meaningful output.
📚 Topics Covered in Day 3
In this lesson, I learned:
- What are strings in Python
- How to take user input using
input() - How to convert input into numbers
- How to format output using f-strings
🔤 What Is a String in Python?
A string is a sequence of characters used to store text.
In Python, strings are written inside double quotes " " or single quotes ' '.
Example:
message = "Hello, Python"
print(message)
Output:
Hello, Python
Strings are commonly used for:
- Names
- Messages
- User input
- Text display
🧾 Taking User Input in Python (input())
The input() function allows Python to receive data from the user.
Example:
name = input("Enter your name: ")
print("Hello", name)
Output:
Enter your name: Hiranmoy
Hello Hiranmoy
By default, input() always returns a string.
🔢 Converting Input into Numbers
When we need to perform calculations, we must convert user input into numbers using int().
Example:
age = int(input("Enter your age: "))
print("After 5 years, your age will be", age + 5)
Output:
Enter your age: 22
After 5 years, your age will be 27
🧠 Formatting Output Using f-Strings
Python provides f-strings to format output easily.
Example:
name = input("Enter your name: ")
city = input("Enter your city: ")
print(f"I am {name} and I live in {city}")
Output:
I am Hiranmoy and I live in Haldia
f-strings make code cleaner and easier to read.
🏗️ Real-Life Example: Online Form
The following program simulates a simple online form:
name = input("Enter your name: ")
age = int(input("Enter your age: "))
profession = input("Enter your profession: ")
city = input("Enter your city: ")
print("\n--- User Details ---")
print(f"Name: {name}")
print(f"Age: {age}")
print(f"Profession: {profession}")
print(f"City: {city}")
This program behaves like filling an online registration form.
🌍 Why This Lesson Is Important
User input and strings are essential in:
- Login systems
- Registration forms
- Chat applications
- Interactive software
This lesson is a foundation for building real-world Python applications.
✅ What I Learned Today
- How to work with strings
- How to take user input
- How to convert input into numbers
- How to format output using f-strings
This lesson helped me build interactive Python programs.
🔜 Next Lesson (Day 4)
In Day 4, I will learn about:
- Conditional statements (
if,else) - Decision making in Python
- Real-life logic examples
📢 Final Note
This Python learning series is written for beginners.
Anyone who wants to learn Python step by step can follow these posts.
Thank you for reading 🚀