py variables ad file nameing rules

This commit is contained in:
2025-08-12 00:56:56 +05:30
commit f1047cea6a
4 changed files with 152 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.venv

12
README.md Normal file
View File

@ -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

69
src/basic/file.md Normal file
View File

@ -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 Pythons built-in math module.
- **Case sensitivity** depends on OS:
- Windows/macOS (default FS): `MyFile.py` == `myfile.py`
- Linux: case-sensitive — theyre 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 its 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)

70
src/basic/variables.py Normal file
View File

@ -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)) # <class 'complex'>
# 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) # <class 'str'>
isinstance(x, str) # True