Python Variables, Data Types, and Basic I/O – A Beginner’s Guide (2025)
What Are Variables in Python?
In Python, a variable functions similarly to a container for data values. Python, in contrast to several other programming languages, determines a variable’s data type automatically depending on the value supplied to it..
Syntax:
pythonCopyEditvariable_name = value
Example:
pythonCopyEditname = "Alice"
age = 25
is_student = True
You can also read:-What is Python?
Best Practices:
- Make use of appropriate variable names, such as total_price and user_name.
- Observe the snake_case naming scheme.
- Don’t name variables with Python reserved keywords.
Data Types in Python
Python provides a number of built-in data types and is a dynamically typed language.
🔹 1. Numeric Types
- int – Integer numbers
- float – Decimal numbers
- complex – Complex numbers
pythonCopyEditx = 10 # int
y = 3.14 # float
z = 2 + 3j # complex
🔹 2. Text Type
- str – String of characters
pythonCopyEditgreeting = "Hello, Python!"
🔹 3. Boolean Type
- bool – Represents
TrueorFalse
pythonCopyEditis_active = True
🔹 4. Sequence Types
- list – Ordered and mutable
- tuple – Ordered and immutable
- range – Sequence of numbers
pythonCopyEditmy_list = [1, 2, 3]
my_tuple = (4, 5, 6)
my_range = range(1, 5)
🔹 5. Mapping Type
- dict – Key-value pairs
pythonCopyEditstudent = {"name": "John", "age": 22}
🔹 6. Set Types
- set – Unordered and no duplicate elements
pythonCopyEditmy_set = {1, 2, 3, 3}
🔹 7. None Type
- Represents the absence of a value
pythonCopyEditx = None
Basic Input and Output in Python
🟡 Input from the User
Use the input() function to get information from the user. By default, it gives back a string.
pythonCopyEditname = input("Enter your name: ")
print("Hello,", name)
Convert input to another data type:
pythonCopyEditage = int(input("Enter your age: "))
print("You will be", age + 1, "next year.")
Output in Python
The print() function is used to display output.
pythonCopyEditprint("Welcome to Python Programming!")
Format strings using:
- f-strings (Python 3.6+)
pythonCopyEditname = "Alice"
print(f"Hello, {name}")
- .format() method
pythonCopyEditprint("Hello, {}".format(name))
Mini Project: Greet the User
pythonCopyEdit# A simple input/output example
name = input("What's your name? ")
age = int(input("How old are you? "))
print(f"Hi {name}, you are {age} years old!")
Conclusion
Every newcomer studying Python must comprehend variables, data types, and fundamental I/O operations. These ideas serve as the cornerstone for creating dynamic, readable, and useful programs.
You might be like this:-
Data Visualization In Data Science: Tools, Best Practices-2025

Leave a Reply