Ready to dive into the world of Python programming? You're in luck! Today, we're embarking on an exciting journey to learn Python, the second most popular programming language in the world, through a comprehensive guide tailored just for you in Sinhala, the language of Sri Lanka. Whether you're a beginner eager to explore the world of coding or an experienced developer looking to expand your skill set, this Python tutorial is designed to cater to all levels.

Why Python, you ask? Python is an interpreted, high-level, and general-purpose programming language that's easy to learn, read, and write. It supports multiple programming styles, including procedural, object-oriented, and functional programming. From data analysis and machine learning to web development and automation, Python is versatile and incredibly powerful. So, let's roll up our sleeves and get started!

Getting Started with Python
Before we dive into the nitty-gritty of Python, let's first ensure you have the right tools to kickstart your learning journey.

1. **Python Installation**: Download and install Python from the official website (https://www.python.org/downloads/), ensuring you tick the 'Add Python to PATH' option during installation. This will allow you to run Python commands directly from your command prompt or terminal.
Python Environment Setup

For better organization and isolation of your projects, it's recommended to use a virtual environment.
First, open your command prompt or terminal and check if Python is installed correctly by typing:
```bash python --version ```
If the output displays a Python version number (e.g., Python 3.8.5), your installation is successful. Now, create a virtual environment using the following command:

```bash python -m venv myenv ```
Then activate the environment:
```bash # On Windows myenv\Scripts\activate # On macOS and Linux source myenv/bin/activate ```
Python Integrated Development Environments (IDEs)
While you can code in Python using any text editor, using an IDE can drastically improve your productivity and development experience. Popular Python IDEs include:

- PyCharm (https://www.jetbrains.com/pycharm/)
- Visual Studio Code (https://code.visualstudio.com/) with the Python extension
- Thonny (https://thonny.org/) – a beginner-friendly IDE
Python Basics: Syntax and Data Types















![The Complete Python 3 Beginners Tutorial [Full Course] | Coding Made Easy | Learn Python](https://i.pinimg.com/originals/e5/c2/49/e5c249947c23593e25e78baed002d89e.jpg)



Now that we have our environment set up, let's dive into the core concepts of Python – syntax and data types.
Python uses indentation to define blocks of code. The standard indentation is 4 spaces or a tab. Here's a basic 'Hello, World!' example:
```python print("Hello, World!") ```
Basic Data Types
Python supports various data types, including:
- Numeric Types: int, float, complex
- Text Type: str
- Sequence Types: list, tuple, range
- Mapping Type: dict
- Set Types: set, frozenset
- Boolean Type: bool
Here's how you can assign values to these data types:
```python # Integer x = 5 # Float y = 3.14 # String name = "John Doe" # List fruits = ["apple", "banana", "cherry"] # Tuple point = (3, 5) # Dict student = { "name": "Jane Doe", "age": 20 } # Set unique_numbers = {1, 2, 3, 4, 5} # Boolean is_learning = True ```
Variables and Naming Conventions
Variables in Python are used to store data values. Following a good naming convention makes your code more readable and maintainable. Here are some naming guidelines:
- Variable names should be descriptive and lowercase, with words separated by underscores (snake_case).
- Use singular or plural nouns for variable names, e.g., user_name.
For example, consider the following valid variable names:
```python user_name = "John Doe" age_in_years = 30 is_student = False ```
Python Control Flow: If-elif-else Statements and Loops
Now that we're familiar with Python's basics, let's explore how to control the flow of our programs using conditional statements and loops.
In Python, the if-elif-else statement allows you to execute different blocks of code based on given conditions:
```python age = 15 if age < 18: print("You are a minor.") elif 18 <= age < 60: print("You are an adult.") else: print("You are a senior citizen.") ```
Loops: for and while
Python offers two types of loops: for loops for iterating over sequences (like lists, tuples, or strings), and while loops for iterative execution based on a condition.
Here's an example of each:
```python # For loop fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit) # While loop i = 0 while i < 5: print(i) i += 1 ```
You can also use the break, continue, and pass statements to control the flow of your loops:
- break: Terminates the loop prematurely.
- continue: Skips the current iteration and moves to the next one.
- pass: A placeholder for future code or when no action is required.
Now that you've learned the basics of Python, it's time to apply your newfound knowledge and start creating some awesome projects! Stay curious, and happy coding!