{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreif2ynzuoq6k5mcx6sk6m5enxhfp6m34bblal3sufkryjhrpaugdve",
    "uri": "at://did:plc:25rdn5elo5izoxrmtis34zuk/app.bsky.feed.post/3moowqtrxuvi2"
  },
  "coverImage": {
    "$type": "blob",
    "ref": {
      "$link": "bafkreie7dvjoxwqfskw6tcmfyawhjz7hzsuuz4hdw7r6xugkxsvd6xxxoy"
    },
    "mimeType": "image/webp",
    "size": 66138
  },
  "path": "/ramesh_s_a8f0867d239e927c/python-for-beginners-part-2-variables-data-types-numbers-mja",
  "publishedAt": "2026-06-20T03:29:52.000Z",
  "site": "https://dev.to",
  "tags": [
    "ai",
    "python",
    "programming",
    "webdev",
    "Part 1",
    "Part 1: Getting Started & Syntax"
  ],
  "textContent": "_Part 2 of a beginner-friendly series on learning Python from scratch._\n\nIn Part 1, we installed Python, wrote our first program, and learned the syntax rules that hold everything together. Now it's time to start storing and working with information — which means variables and data types.\n\n##  What is a Variable?\n\nA variable is a name that points to a value stored in memory. Think of it as a labeled container you can put something into, and refer back to later by name.\n\n\n\n    name = \"Ramesh\"\n    age = 25\n\n\nUnlike many other languages, Python doesn't need you to declare a variable's type ahead of time. You just assign a value with `=`, and Python figures out the type on its own. This is called **dynamic typing**.\n\n\n\n    x = 5        # x is an integer\n    x = \"hello\"  # now x is a string — totally legal in Python\n\n\nThis flexibility is convenient, but it also means you need to be a little more careful — Python won't stop you from changing a variable's type halfway through your program, even if that wasn't your intention.\n\n##  Variable Naming Rules\n\nPython is strict about how variable names can look:\n\n  * Must start with a letter or an underscore (`_`) — never a number.\n  * Can only contain letters, numbers, and underscores.\n  * Cannot be a Python keyword (`class`, `for`, `if`, etc.).\n  * Are case-sensitive — `age`, `Age`, and `AGE` are three different variables.\n\n\n\n\n    age = 25        # valid\n    _age = 25       # valid\n    age2 = 25       # valid\n    2age = 25       # invalid — cannot start with a number\n    my-age = 25     # invalid — hyphens aren't allowed\n\n\n###  Naming conventions\n\nPython's style guide (PEP 8) recommends `snake_case` for variable names — lowercase words separated by underscores:\n\n\n\n    first_name = \"Ramesh\"\n    total_score = 95\n\n\n##  Assigning Multiple Variables\n\nPython lets you assign several variables in a single line, which keeps code compact and readable.\n\n\n\n    # One value to multiple variables\n    x = y = z = 10\n\n    # Multiple values to multiple variables\n    name, age, city = \"Ramesh\", 25, \"Chennai\"\n\n\n##  Data Types in Python\n\nEvery value in Python belongs to a data type, which determines what kind of operations you can perform on it. Here are the core built-in types you'll use constantly:\n\nType | Example | Description\n---|---|---\n`str` | `\"hello\"` | Text\n`int` | `25` | Whole numbers\n`float` | `3.14` | Decimal numbers\n`bool` |  `True` / `False` | Logical values\n`list` | `[1, 2, 3]` | Ordered, changeable collection\n`tuple` | `(1, 2, 3)` | Ordered, unchangeable collection\n`dict` | `{\"a\": 1}` | Key-value pairs\n`set` | `{1, 2, 3}` | Unordered, unique values\n`NoneType` | `None` | Represents \"no value\"\n\nWe'll dive deep into collections (list, tuple, dict, set) in Part 5. For now, let's focus on the basics — strings, numbers, and booleans.\n\n###  Checking a variable's type\n\nUse the built-in `type()` function any time you want to confirm what you're working with:\n\n\n\n    x = 25\n    print(type(x))     # <class 'int'>\n\n    y = \"hello\"\n    print(type(y))     # <class 'str'>\n\n\nThis is one of the most useful debugging habits you can build early on.\n\n##  Numbers in Python\n\nPython has three numeric types you'll run into regularly:\n\n  * **`int`** — whole numbers, positive or negative, with no limit on size: `10`, `-45`, `1000000`\n  * **`float`** — numbers with a decimal point: `3.14`, `-0.5`, `2.0`\n  * **`complex`** — numbers with an imaginary part, written with a `j`: `3 + 4j` (rare for beginners, but good to know it exists)\n\n\n\n\n    x = 10        # int\n    y = 3.14      # float\n    z = 3 + 4j    # complex\n\n    print(type(x), type(y), type(z))\n\n\n###  Basic arithmetic\n\nPython supports all the math operations you'd expect:\n\n\n\n    a = 10\n    b = 3\n\n    print(a + b)   # 13  → addition\n    print(a - b)   # 7   → subtraction\n    print(a * b)   # 30  → multiplication\n    print(a / b)   # 3.333... → division (always returns a float)\n    print(a // b)  # 3   → floor division (drops the decimal)\n    print(a % b)   # 1   → modulus (remainder)\n    print(a ** b)  # 1000 → exponent (a to the power of b)\n\n\nNote that `/` always returns a `float`, even if the result is a whole number:\n\n\n\n    print(10 / 2)   # 5.0, not 5\n\n\n##  Type Casting\n\nSometimes you need to convert a value from one type to another — this is called **casting**. Python gives you simple functions for this:\n\n\n\n    x = \"25\"\n    y = int(x)      # converts string \"25\" to integer 25\n\n    a = 25\n    b = str(a)      # converts integer 25 to string \"25\"\n\n    c = \"3.14\"\n    d = float(c)    # converts string \"3.14\" to float 3.14\n\n\nThis comes up constantly in real programs — for example, when you take user input (which always arrives as a string) and need to do math with it:\n\n\n\n    user_input = input(\"Enter your age: \")  # this is a string, even if you type \"25\"\n    age = int(user_input)                   # now it's a usable integer\n    print(age + 5)\n\n\nIf you try to do math directly on the unconverted string, Python will raise a `TypeError` — so casting isn't optional here, it's required.\n\n##  Why This Matters\n\nDynamic typing is one of the reasons Python feels fast to write in — you spend less time declaring types and more time solving the actual problem. But that same flexibility is also where beginners get tripped up: a variable that started as a number can quietly become a string somewhere in your code, and the bug only shows up when you try to do math on it. Getting comfortable with `type()` and casting early will save you a lot of confusion later.\n\n##  What's Next\n\nIn Part 3, we'll cover **strings and booleans** — how to slice and format text, the most useful string methods, and how Python handles `True`/`False` logic.\n\n_This is Part 2 of an 8-part beginner Python series. Catch up on Part 1: Getting Started & Syntax, or continue to Part 3 once it's live._",
  "title": "Python for Beginners — Part 2: Variables, Data Types & Numbers"
}