Introduction:
Welcome to Darchums Technologies! In this tutorial, we’re diving into the world of Python — one of the most powerful, beginner-friendly, and in-demand programming languages today. Whether you're just getting started or need a refresher, this tutorial will guide you step-by-step with real examples.Why Learn Python?
-
Easy to read and write
-
Versatile: Web dev, AI, Data Science, Games, Automation
-
Huge community and libraries
1. Setting Up Python
Step 1: Download Python from python.org
Step 2: Install it and tick “Add Python to PATH”
Step 3: Open your terminal or IDLE (comes with Python)
To confirm installation:
>>> python --version
2. Your First Python Program
Create a file named hello.py
and add:
print ("Hello, world!")
Run it:
python hello.py
(This will output, Hello, world!)
Kudos! You've just written your first program.
3. Variables and Data Types
type ()
to check:4. Basic Operations
🧠Explanation:
-
"Hello"
is a string. -
" "
is a space. -
name
contains"Darchums"
. -
When you use the
+
operator with strings, it joins them together (this is called string concatenation).
5. Control Flow (if/else)
🧠Explanation:
-
age = 25
→ This assigns the value 25 to the variableage
. -
The condition
age > 18
is True, since 25 is greater than 18. -
Therefore, the code inside the
if
block runs:print("You are an adult.")
-
The
else
block is ignored because the condition was already satisfied.
If you change age = 15
, the output would then be:
("you are a minor")
6. Loops
7. Functions
8. Lists and Dictionaries
🧠Explanation:
-
Lists in Python are zero-indexed, which means:
-
fruits[0]
→"apple"
-
fruits[1]
→"banana"
-
fruits[2]
→"cherry"
-
So print(fruits[1])
prints "banana
🧠Explanation:
-
A dictionary stores data in key-value pairs.
-
"name"
is a key, and its value is"Darlington"
. -
So
user["name"]
retrieves and prints that value.
9. Errors and Debugging
-
10 / 0
would normally cause a ZeroDivisionError, because you can't divide a number by zero. -
But since it's inside a
try
block, Python doesn't crash. Instead, it jumps to theexcept
block. -
The message
"Cannot divide by zero."
is printed instead.
10. Final Project: Simple Calculator
Conclusion
Now you’ve made your first steps in Python! Practice every day, experiment, and don’t fear errors — they are part of learning.
Stay tuned for more in-depth tutorials right here on Darchums Technologies! -Learn, Code, Create.
Comments
Post a Comment