Wednesday, June 25, 2025

basic/fundamental concepts of Python

Here’s a list of the basic/fundamental concepts of Python that every beginner should learn:


✅ 1. Python Syntax & Structure

  • How to write and run Python code

  • Indentation (very important in Python)

  • Comments (# for single-line, ''' ''' or """ """ for multi-line)


✅ 2. Variables and Data Types

  • Assigning values to variables

  • Common data types:

    • int (integers)

    • float (decimals)

    • str (strings/text)

    • bool (True/False)

name = "Raj"
age = 25
height = 5.7
is_student = True

✅ 3. Operators

  • Arithmetic: +, -, *, /, //, %, **

  • Comparison: ==, !=, >, <, >=, <=

  • Logical: and, or, not

  • Assignment: =, +=, -=, etc.


✅ 4. Control Flow

  • Conditional Statements: if, elif, else

if age > 18:
    print("Adult")
  • Loops:

    • for loop (used for iterating)

    • while loop (runs as long as condition is true)

for i in range(5):
    print(i)

✅ 5. Data Structures

  • Lists: ordered, changeable

    fruits = ["apple", "banana", "cherry"]
    
  • Tuples: ordered, unchangeable

    point = (4, 5)
    
  • Dictionaries: key-value pairs

    student = {"name": "Raj", "age": 20}
    
  • Sets: unordered, no duplicates

    numbers = {1, 2, 3}
    

✅ 6. Functions

  • Define reusable blocks of code

def greet(name):
    return "Hello " + name

✅ 7. Input and Output

  • Taking user input: input()

  • Printing output: print()

name = input("Enter your name: ")
print("Hello", name)

✅ 8. Type Casting

  • Converting between types:

age = int("25")
height = float("5.9")

✅ 9. Error Handling (Try/Except)

  • Catch and handle errors:

try:
    x = 10 / 0
except ZeroDivisionError:
    print("Cannot divide by zero")

✅ 10. Basic File Handling

  • Open, read, write, and close files

with open("file.txt", "r") as f:
    content = f.read()