Introduction to Basic Language Syntax - Naresh IT
Python Basics: Variable Declarations, Data Types, and Control Structures
1. Variable Declarations in Python
Unlike other languages like Java or C++, Python does not require explicit variable declaration with a specific data type. You can directly assign a value to a variable.
Syntax for Variable Declaration:
Python is dynamically typed, meaning the type is inferred automatically.
Examples:
2. Data Types in Python
Python has several built-in data types. Some common ones are:
| Data Type | Example | Description |
|---|---|---|
| int | x = 10 | Whole numbers |
| float | y = 3.14 | Decimal numbers |
| str | name = "Sruthi" | Text (String) |
| bool | status = True | Boolean values (True/False) |
| list | fruits = ["Apple", "Banana"] | Ordered, mutable collection |
| tuple | coords = (4, 5) | Ordered, immutable collection |
| set | unique_nums = {1, 2, 3} | Unordered, unique items |
| dict | student = {"name": "Grace", "age": 22} | Key-Value pairs |
Example of Type Checking:
3. Control Structures in Python
Control structures allow us to control the flow of execution.
A. Conditional Statements (if, elif, else)
Used for decision-making.
B. Looping Structures
Loops help execute code multiple times.
1. for Loop:
Used for iterating over sequences (list, tuple, range, etc.).
2. while Loop:
Runs until the condition is False.
3. Loop Control Statements:
break→ Exits the loop early.continue→ Skips the current iteration.pass→ Placeholder, does nothing.

Comments
Post a Comment