💻🐍📘 Programming in Python
👉 Introduction to Python 🐍
➥Python is a high-level, interpreted, general-purpose programming language.
➭Created by Guido van Rossum in 1991.
➭Focus on simplicity, readability, and rapid development.
➭Widely used in AI, Data Science, Web development, Cyber Security, Automation & Scripting, Mobile & Game Apps.
📌 Why is Python Popular? ⭐
➭Easy to learn for beginners.
➭Huge collection of libraries.
➭Works on Windows, Mac, and Linux.
➭Used by industry giants: Google, NASA, Netflix.
👉 Features of Python ⚙️
1️⃣ Python is Easy to Use ✍️
➭Python is a very developer-friendly language.
➭Very simple and clear syntax — similar to English.
➭Anyone can start learning it in a few hours or days.
➭Compared to object-oriented languages like Java, C, C++, C#, Python is the easiest to learn.
Example:
print("Hello World")
2️⃣ Python is Powerful 🚀
➭Python is a high-level, powerful programming language.
➭Used by big companies like Google, IBM, Microsoft, NASA, Intel etc.
➭Supports AI, Machine Learning, Data Science, Web Development and many more fields.
➭Trusted by professional programmers all over the world.
3️⃣ Python as a "Glue" Language 🔗
➭Python can easily connect (integrate) with other languages like C, C++, Java.
➭Programmers can reuse existing code written in these languages and combine it with Python.
➭Very useful for scientific computing, robotics, automation, etc.
4️⃣ Python Runs Everywhere 🌐
➭Python is platform independent.
➭Python programs run on Windows, Mac OS, Linux, Unix and even small devices like Raspberry Pi.
5️⃣ Python is Free and Open Source 🆓
➭Python is 100% free to download and use.
➭Anyone can copy, share or modify Python because it is open source.
➭Python is regularly updated and improved by a large global community of developers.
👉 Installing Python on Windows 💻
🖥️ Easy Step-by-Step Guide
Step 1: Visit Python's Official Website
➭Open your browser and go to: www.python.org
Step 2: Go to Downloads Section
➭Click on Downloads in the menu.
➭A page will appear showing the latest Python version for Windows.
Step 3: Choose Your Windows Installer
➭Scroll down to find the Windows installers.
➭For 32-bit system: choose Windows Installer (32-bit).
➭For 64-bit system: choose Windows Installer (64-bit).
➭(Most modern computers are 64-bit.)
Step 4: Install Python
➭After downloading, double-click the installer file.
➭VERY IMPORTANT: Tick the box “Add Python to PATH” at the bottom.
➭Click Install Now and follow the on-screen instructions.
Step 5: Verify Installation
➭Open Command Prompt (CMD).
➭Type:
python --version
➭If Python is installed correctly, the Python version number will be displayed.
👉 Displaying Strings in Python 🖥️
print("Welcome to Python Programming")
📌 Escape Sequences 🎯
| Code | Meaning |
|---|---|
| \n | New Line |
| \t | Tab Space |
| \" | Double Quote |
| \' | Single Quote |
print("Hello\nPython")
print("Name:\tPratap")
👉 Programming in Script Mode 🧾
🔹 What is Script Mode?
➭ Script Mode means writing Python programs in a .py file.
➭ It is used for long programs and saved for future use.
✨ Features of Script Mode
1️⃣ Code is Written in a File:
➭ Programs are saved with .py extension.
➭ Example: hello.py, area.py
2️⃣ Useful for Long Programs:
➭ Better for writing many lines of code.
➭ Easier than typing commands one by one in Python Shell.
3️⃣ Easy to Save & Reuse:
➭ You can save, open, and edit your code anytime.
📌 How to Write a Program in Script Mode
Step 1: Open IDLE
➭ Start Python’s IDLE editor.
Step 2: Open a New File
➭ Go to File → New File.
Step 3: Type Your Program
print("Welcome to Python")
Step 4: Save the File
➭ Click File → Save and save as welcome.py.
Step 5: Run the Program
➭ Click Run → Run Module or press F5.
➭ Output shows in the Python Shell.
✔ Example Program in Script Mode
Program:
a = 10
b = 20
sum = a + b
print("Sum =", sum)
Output:
Sum = 30
👉 Python Comments 💬
➭ Comments are notes in a program that Python does not run.
➭ Used to explain code.
Types:
1️⃣ Single-Line Comment: Starts with #
# This is a comment
2️⃣ Multi-Line Comment: Written using ''' ''' or """ """
''' This is multi-line comment '''
👉 Displaying Strings in Python 💻
➭ Strings are shown using the print() function.
Example:
print("Hello, Python!")
Output:
Hello, Python!
➭ Strings can be in single quotes ' ' or double quotes " " .
Example:
print('Hello')
print("Python")
Output:
Hello Python
👉 Python Statements 🧾
1️⃣ Line Continuation
➭ Use \ to split a long statement.
total = 10 + 20 + \
30 + 40
print(total)
2️⃣ Variable
➭ Stores values to use later.
age = 15 name = "Alice"
3️⃣ Display Value
print(age) print(name)
4️⃣ Accept Input from User
age = input("Enter your age: ")
print("Your age is", age)
5️⃣ Converting Values
➭ Input is string by default. Convert using int(), float() etc.
age = int(input("Enter your age: "))
print("Next year you will be", age + 1)
👉 Numbers in Python 🔢
➥ int: Whole numbers (e.g., 5, 10, 100)
➥ float: Decimal numbers (e.g., 3.5, 12.5)
➥ complex: Numbers in a + bj format
a = 10 b = 12.5 c = 4 + 3j
👉 Type Conversion 🔄
➭ Convert values using int(), float(), str().
x = int("25") # string to int
y = float("12.5") # string to float
z = str(100) # int to string
👉 Python Operators & Operations ➗
1️⃣ Arithmetic Operators ➕
➭ Used for mathematical calculations: +, -, *, /, %, //, **
a = 10 b = 3 print(a + b) # 13 print(a ** b) # 1000 (10^3)
| Operator | Meaning |
|---|---|
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| % | Modulus |
| ** | Exponent |
| // | Floor Division |
2️⃣ Relational / Comparison Operators 🤝
➭ Compare values and return True or False: ==, !=, >, <, >=, <=
a = 10 b = 20 print(a < b) # True
| Operator | Meaning |
|---|---|
| == | Equal |
| != | Not equal |
| > | Greater than |
| < | Less than |
| >= | Greater or equal |
| <= | Less or equal |
3️⃣ Logical Operators 🤔
➭ Used for combining conditions: and, or, not
a = True b = False print(a and b) # False print(a or b) # True print(not a) # False
| Operator | Meaning |
|---|---|
| AND | Both true |
| OR | At least one true |
| NOT | Reverse condition |
4️⃣ Assignment Operators 📝
➭ Used to assign or update values of variables: =, +=, -=, *=, /=, %=, //=, **=
x = 10 x += 5 # x = 15 x *= 2 # x = 30
| Operator | Meaning |
|---|---|
| = | Assign value |
| += | Add & assign |
| -= | Subtract & assign |
| *= | Multiply & assign |
| /= | Divide & assign |
| %= | Modulus & assign |
| //= | Floor divide & assign |
| **= | Power & assign |
No comments:
Post a Comment