commit f1047cea6ad9f3077076fef8b61bf49dc400591f Author: anivkuttan Date: Tue Aug 12 00:56:56 2025 +0530 py variables ad file nameing rules diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b694934 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f7dcb84 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Python + +Checking Python version on Windows machine +py -3 --version + +Linux/macOS +python3 --version + +if this comments give error make sure you installed the python +link -> https://www.python.org/downloads/ + +Python in VS Code diff --git a/src/basic/file.md b/src/basic/file.md new file mode 100644 index 0000000..1ef1edb --- /dev/null +++ b/src/basic/file.md @@ -0,0 +1,69 @@ +# Python File Naming & Interpreter Requirements + +## 1. Technical Rules (Python Interpreter Requirements) + +- **File extension** must be `.py` for a normal Python source file. +- **No spaces** — Python allows them, but spaces in filenames make imports painful. + ❌ `my script.py` → `import my script` ❌ (syntax error) + ✅ Use underscores: `my_script.py` +- Only letters, numbers, and underscores are safe. + Allowed: `a_z0_9` + Avoid: `-` (hyphen), `@`, `#`, `.` (except before `.py`) +- Must not start with a number (if you plan to import it). + ❌ `123module.py` → import fails + ✅ `module123.py` +- Avoid same name as Python standard library modules (to prevent shadowing). + ❌ `math.py` → will block importing Python’s built-in math module. +- **Case sensitivity** depends on OS: + - Windows/macOS (default FS): `MyFile.py` == `myfile.py` + - Linux: case-sensitive — they’re different files. + +--- + +## 2. PEP 8 Style Recommendations (Best Practices) + +- Use lowercase letters. +- Use underscores (`snake_case`) for readability. + ✅ `data_parser.py` + ✅ `config_loader.py` +- Keep names short but descriptive. +- Avoid overly generic names like `test.py`, `main.py` unless their role is obvious. +- If it’s a package directory, include an `__init__.py` file. + +--- + +## 3. Special Cases + +**a) `__init__.py`** + +- Marks a directory as a Python package. +- Can be empty or hold package-level imports. + +**b) `__main__.py`** + +- Lets a package run with: + ```bash + python -m package_name + ``` + +**c) Dunder files (`__something__.py`)** + +- Reserved for Python internals (e.g., `__init__.py`, `__main__.py`). +- Avoid naming your own files like this unless required. + +--- + +## 4. Good Examples + +✅ `data_cleaner.py` +✅ `user_auth.py` +✅ `ml_model_training.py` + +--- + +## 5. Bad Examples + +❌ `data cleaner.py` (space) +❌ `DataCleaner.py` (CamelCase is discouraged for files, reserved for classes) +❌ `math.py` (shadows standard library) +❌ `my-script.py` (hyphen breaks import) diff --git a/src/basic/variables.py b/src/basic/variables.py new file mode 100644 index 0000000..153e2c7 --- /dev/null +++ b/src/basic/variables.py @@ -0,0 +1,70 @@ +# Declaring Variables +# No var, let, or const keywords. +# Type is inferred from the assigned value. + +# Core Primitive Types +whole_number = 10 # int whole numbers +normal_text = "Hello" # str text +decimal_value = 3.14 # float decimal numbers +# boolean True / False Subclass of int (bool behaves like int) +is_eligible = True +# True + True # 2 +name = None # NoneType null + +# Integers +x = 42 +print(type(x)) + +# Floating-Point Numbers +y = 3.14 +print(type(y)) + +# Complex Numbers +z = 2 + 3j +print(type(z)) # + +# str(Standard String) +single_qoutes = 'World' +double_quotes = "Hello" +multiline = """This is +a multi-line +string.""" + +# f-Strings +name = "Ani" +f"Hello, {name.upper()}!" +print(f"{name}") +print(F"{name}") + + +s = "Python" +s[::-1] # Reverse + + +# Type Hints +name: str = "Anikuttan" +age: int = 78 + +# Special / Advanced Types +b = b"hello" # bytes (immutable) +ba = bytearray(b"hello") # mutable +m = memoryview(b) # zero-copy slice view + +# Multiple Assignment +a, b, c = 1, 2, 3 +x = y = z = 10 + +# Unpacking +numbers = [1, 2, 3] +a, b, c = numbers +a, *rest = range(5) # a = 0, rest = [1, 2, 3, 4] + +# Swapping +x, y = y, x + +# Dynamic Typing & Type Checking +x = 42 +x = "string now" # Allowed + +type(x) # +isinstance(x, str) # True