𝗣𝘆𝘁𝗵𝗼𝗻 𝗳𝗼𝗿 𝗕𝗲𝗴𝗶𝗻𝗻𝗲𝗿𝘀: 𝗩𝗮𝗿𝗶𝗮𝗯𝗹𝗲𝘀 𝗮𝗻𝗱 𝗗𝗮𝘁𝗮 𝗧𝘆𝗽𝗲𝘀

You learned how to install Python and write your first program in Part 1. Now you must learn how to store information.

A variable is a name for a value in memory. Think of it as a labeled box. You put data inside the box and use the label to find it later.

Example: name = "Ramesh" age = 25

Python uses dynamic typing. This means you do not need to tell Python what kind of data a variable holds. It figures it out. You can even change the data type later.

x = 5 x = "hello"

This flexibility makes coding fast. However, you must watch your code to avoid mistakes.

Variable Name Rules:

  • Start with a letter or an underscore (_).
  • Do not start with a number.
  • Use only letters, numbers, and underscores.
  • Do not use Python keywords like class or if.
  • Remember that names are case-sensitive. age and Age are different.

Use snake_case for your names. This means lowercase words with underscores. Example: first_name = "Ramesh"

Core Data Types:

  • str: Text like "hello"
  • int: Whole numbers like 25
  • float: Decimals like 3.14
  • bool: True or False
  • list: An ordered collection
  • dict: Key-value pairs

Use the type() function to check what you are working with. This helps you find errors quickly.

Python handles math easily:

    • Addition
    • Subtraction
    • Multiplication
  • / Division (always results in a float)
  • // Floor division (removes the decimal)
  • % Modulus (finds the remainder)
  • ** Exponent

Sometimes you must change a type. This is called casting. If a user types 25, Python sees it as a string. You must convert it to an integer to do math.

Example: user_input = "25" age = int(user_input) print(age + 5)

Master these basics to avoid bugs. In Part 3, we cover strings and booleans.

Source: https://dev.to/ramesh_s_a8f0867d239e927c/python-for-beginners-part-2-variables-data-types-numbers-mja

Optional learning community: https://t.me/GyaanSetuAi