๐ Python Tutorial for Absolute Beginners
๐ Topic: Python Intro + Install, Hello World + Comments, Variables & Data Types
๐น 1. Introduction to Python
What is Python?
Python is a high-level, interpreted, general-purpose programming language that is known for its simplicity and readability. It is widely used in web development, data science, artificial intelligence, machine learning, automation, and more.
Key Features of Python:
-
Easy-to-read syntax
-
Large standard library
-
Dynamically typed
-
Open-source and community-driven
-
Cross-platform
-
Extensive third-party modules (e.g., NumPy, pandas, Django)
Why Learn Python?
-
Beginner-friendly
-
Versatile and powerful
-
In-demand skill for jobs in tech, data, and science
-
Great community and resources
๐น 2. Installing Python
Step-by-Step Installation Guide:
✅ For Windows:
-
Download the latest version (e.g., Python 3.12.x).
-
Run the installer.
-
Important: Check the box “Add Python to PATH” before clicking "Install Now".
-
After installation, open Command Prompt and type:
You should see the installed Python version (e.g.,
Python 3.12.0
).
✅ For macOS:
-
Use Homebrew (recommended):
-
Or download from python.org.
✅ For Linux:
Install via terminal:
Check version:
๐น 3. Writing Your First Python Program (Hello World)
Using the Command Line
-
Open your terminal or command prompt.
-
Type:
-
Enter:
You should see:
Using a Script File
-
Open a code editor like VS Code, Sublime Text, or Thonny.
-
Create a new file and name it
hello.py
. -
Write the following code:
-
Save the file.
-
Run the script from terminal:
๐น 4. Comments in Python
Comments help you explain what your code does. Python supports:
๐ธ Single-Line Comments
Use #
before the comment:
๐ธ Multi-Line Comments
Use triple quotes ('''
or """
):
Note: Triple quotes are also used for documentation (docstrings).
๐น 5. Variables in Python
What is a Variable?
A variable is a name that refers to a value stored in memory.
Rules for Naming Variables:
-
Must start with a letter or underscore
_
-
Cannot start with a number
-
Can include letters, numbers, and underscores
-
Are case-sensitive (
name
andName
are different)
Example:
๐น 6. Python Data Types
Python is dynamically typed, meaning you don’t need to declare a type—it figures it out.
Here are the most commonly used data types:
6.1 ๐ข Numbers
Integer (int
):
Float (float
):
Complex (complex
):
6.2 ๐ค Strings
Strings are sequences of characters.
You can use single '
or double "
quotes:
6.3 ✅ Booleans
Only two boolean values: True
and False
6.4 ๐ฆ Lists
Lists are ordered, mutable, and can hold mixed types.
6.5 ๐ฆ Tuples
Tuples are like lists but immutable.
6.6 ๐งพ Dictionaries
Dictionaries store key-value pairs
6.7 ๐ข Sets
Sets are unordered, and no duplicate values.
๐น 7. Type Casting
Convert between data types using casting functions.
Casting functions:
-
int()
-
float()
-
str()
-
bool()
๐น 8. The type()
and id()
Functions
-
type(variable)
→ returns the type of the value. -
id(variable)
→ returns the unique memory location.
๐น 9. Best Practices for Beginners
-
Use clear, meaningful variable names.
-
Add comments where needed.
-
Keep your code clean and consistent.
-
Use an IDE or code editor with syntax highlighting.
-
Practice often!
๐น 10. What’s Next?
Now that you understand the basics:
-
✅ Install Python
-
✅ Run your first program
-
✅ Use comments
-
✅ Declare variables
-
✅ Work with data types
Next topics to learn:
-
Control Flow (
if
,else
,elif
) -
Loops (
for
,while
) -
Functions
-
Error handling
-
Object-Oriented Programming
๐ฏ Conclusion
Python is an excellent first language, and now you’ve taken your first big step. Practice writing small scripts, experiment with variables and data types, and build your confidence!