🚀 Basics of Python – A Beginner's Guide
✅ What is Python?
Python is a high-level, interpreted programming language known for its easy and readable syntax. It’s widely used in fields like:
-
Web development
-
Data science
-
Machine learning
-
Automation
-
Scripting
Its simplicity makes it an ideal choice for beginners.
✅ Installing Python
- Download Python from https://www.python.org
- Install it, and during installation, check the box "Add to PATH"
- Verify installation using:
Here we are going to use the interpreter for python that is pycharm.
✅ Writing Your First Python Program:
Create a file named hello.py and write:
Going to write our first Program to print any text or any statement in python.
For that purpose we uses the function called "print()".
Syntax to use print() is as follow:
print("Type the statement here that you want to print")
Example: Print("Hello Python")
Output: Hello Python
✅ Python Syntax and Data Types
➡️ Variables
A variable is used to store data. Python is dynamically typed, so you don’t need to declare the type explicitly:
name = "Raghav" # String
age = 25 # Integer
height = 5.9 # Float
is_coder = True # Boolean
➡️ Data Types:
| Data Type | Example | Description |
|---|
int | 10, -5, 0 | Whole numbers |
float | 3.14, -2.5 | Decimal numbers |
str | "Hello" | Text values |
bool | True,False | Boolean values |
list | [1, 2, 3] | Ordered, mutable collection |
1. input():
The input() function allows user input from the keyboard.
Syntax:
prompt – A string displayed to the user before taking input
Example:
2. int(), float(), str()
These are type conversion functions:
int() – Converts to integer
int() – Converts to integerfloat() – Converts to float
float() – Converts to floatstr() – Converts to string
str() – Converts to stringExample:
num = int(input("Enter a number: ")) #let the number be 10
print(num * 2) Output: 10*2=20
✅ Conditional Statements
Conditional statements allow decision-making in Python.
3. if, elif, else:
age= int(input("enter the age"))
if age<0:
print(-1*(age))
else:
print(age)
Question: Suppose your father is the head of the labour factory and He wants to sort the name of the labour on the basis of their wadges. Wether they are rich or poor. So, write the programme to help him. ✅ Conclusion
That's all for today’s basic introduction to Python! 🚀
I hope you understood how easy and fun Python can be if you just follow step-by-step. Now, it's your turn to practice the questions I gave at the end — don’t worry, I’ll share the solutions in my next blog.
👉 In the next part, we will dive deeper into loops in Python where you’ll learn how to run your code multiple times without repeating yourself. You can check it out here: Loops in Python – While & For Loops Explained🔄
Keep learning, keep practicing, and coding will become your best friend. See you in the next blog! ✨
2 Comments
Great coding for lerning
ReplyDeleteHelping a lot
ReplyDelete