Skip to main content

Variables & Data Types

 Variables & Data Types


Understanding variables and data types is the first step to becoming a programmer.
These two concepts help computers store, organize, and process information.

Think of them as:

*Variables → containers to store data
*Data Types → what kind of data stored in that container





What is a Variable?


  • A variable is a named storage location in memory that holds a value.

  • You can change it, update it, or use it in calculations.

* In real life:
         Imagine a box with a label.

Label = variable name

Content inside = variable value

Example:

age = 18


Why Do We Need Variables?


  • To store user input

  • To perform calculations

  • To store data from sensors

  • To track score in games

  • To hold login information

  • To save results

  • Without variables,

Computers would have no memory --- just one-time actions.


How to Declare Variables (Examples)

Python
name = "Declare"
score = 95

C
int age = 20;
float height = 5.8;

JavaScript
let city = "Chennai";
const pi = 3.14;


Different languages, different styles --- but same idea.


What Are Data Types?





A data type decides what kind of value a variable can store.

Examples:

Numbers: 18, 3.14

Text: "Hello"

True/False: True

Collection: [1, 2, 3]

Different types of data need different storage and operations.




Basic Data Types  Explained Simple

 Integer (Whole Numbers)


Used for whole numbers:

0, 1, 10, 500, -20

Examples:

age = 18
score = -5


Computers store integers efficiently  no decimals.

Float / Double (Decimal Numbers)

Any number with a decimal:

3.14

99.99

0.5

Examples:

height = 5.7
price = 99.99


Used in:

Banking

Physics

Games

Measurements

AI calculations

String (Text Data)

Represents text — characters inside quotes.

name = "Yuva"
city = "Chennai"


Everything you type inside " "
or ' ' becomes a string.

Even numbers:

"123" → string
123   → number

Boolean (True / False)

Only two values:

  • True

  • False

Used for decisions:

is_logged_in = True
has_money = False


  • This is the core of:

  • IF conditions

  • Login systems

  • Game mechanics

  • Sensors (on/off)

Composite / Advanced Data Types (Intro Level)


These store multiple values at once.

List / Array

  • Ordered collection

  • [10, 20, 30]

  • Dictionary / Object

  • Key → value pair

  • {"name": "Yuva", "age": 18}

Tuple

Fixed group of values

(4, 6, 8)


These are powerful and used in real projects.

Comments

Popular posts from this blog

AI Models

 🤖 AI Models - Basic Usage  Artificial Intelligence tools are transforming the way we learn, research, create content, and solve problems. In this section, we explain how to use popular AI models effectively, even if you are a complete beginner. Our guides focus on real-world usage, step-by-step explanations, and practical examples that anyone can understand. 1. How to Use ChatGPT Effectively Learn how to interact with ChatGPT to get accurate answers, generate ideas, write content, debug code, and improve productivity. We explain best practices, common mistakes, and smart usage tips for students, developers, and creators. Prompting Basics – Beginner Guide Prompting is the key to getting better results from AI. This guide teaches: What a prompt is How to write clear and effective prompts Beginner-friendly prompt structures Examples for learning, writing, coding, and research 2. Gemini – Create AI Images Discover how to use Google Gemini to generate high-quality AI images. Lear...

Compiler & Interpreter

 What is a Compiler & Interpreter Simple Explanation for Beginners When we write programs in languages like Python, C, Java, or JavaScript, computers cannot read them directly. Computers only understand machine language --- numbers like 0 and 1 (binary). So, there must be a translator between human-readable code and machine code. That translator is either a Compiler or an Interpreter. They both do the same goal: Convert your source code → into something the computer can execute. What is a Compiler? Example (Simple View) Your code : Compiler : Executable file (.exe / binary) :Run * Key Features Translates whole code at once Produces an output file Fast execution once compiled Errors must be fixed before running * Used By Languages C C++ Swift Go *Java (Uses compiler) Example of Compilation You write: printf("Hello World"); Compiler checks the entire file. If everything is correct : It creates an executable program. Then you run it. When Do Compilers Show Errors? During the...