Python Dasar Part 1 (Untuk Mapel Informatika Kelas XI SMA/MA Kurikulum Merdeka)
Table of Contents
Introduction
This tutorial is designed to introduce you to the basics of Python programming, specifically tailored for high school students following the Kurikulum Merdeka. Whether you're preparing for a class or simply want to enhance your programming skills, this guide will help you understand fundamental concepts and get started with coding in Python.
Step 1: Setting Up Your Python Environment
Before you start coding, you need to set up your environment. You can use the online platform provided in the video for convenience.
- Visit Python Playground.
- Create a new project or use an existing template.
- Familiarize yourself with the interface, including where to write your code and how to run it.
Step 2: Writing Your First Python Program
Let’s create a simple program that prints a message to the screen.
-
Open your code editor in the Playground.
-
Type the following code:
print("Hello, World!")
-
Run the program by clicking the 'Run' button.
-
Observe the output displayed on the screen.
Practical Advice
- Ensure you have correct syntax; Python is sensitive to indentation and spacing.
- Experiment with changing the message inside the quotes to see how it affects the output.
Step 3: Understanding Variables
Variables are essential in programming as they store data. Here’s how to create and use them.
-
Define a variable by assigning it a value. For example:
name = "Alice" age = 17
-
Print the variable values:
print(name) print(age)
-
Run the code to see the output.
Common Pitfall
- Remember that variable names cannot start with a number and cannot include spaces.
Step 4: Basic Data Types
Familiarize yourself with the basic data types in Python:
- String: Text enclosed in quotes.
- Integer: Whole numbers (e.g., 1, 2, 3).
- Float: Decimal numbers (e.g., 1.5, 2.75).
- Boolean: Represents True or False values.
Example Code
To demonstrate different data types, you can use:
my_string = "Hello"
my_integer = 10
my_float = 10.5
my_boolean = True
print(my_string, my_integer, my_float, my_boolean)
Step 5: Basic Operations
Learn how to perform basic arithmetic operations in Python.
- Addition:
+
- Subtraction:
-
- Multiplication:
*
- Division:
/
Example Code
Here’s how to implement these operations:
a = 5
b = 2
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
Step 6: Creating Simple Functions
Functions allow you to create reusable code blocks.
-
Define a function using the
def
keyword:def greet(): print("Hello, welcome to Python!")
-
Call the function:
greet()
Practical Tip
- Use functions to organize your code and avoid repetition.
Conclusion
In this tutorial, you’ve learned how to set up your Python environment, write your first program, and understand basic concepts like variables, data types, operations, and functions.
Next steps could include exploring more advanced topics like loops and conditionals, or diving deeper into Python libraries for data analysis or web development. Keep practicing, and don’t hesitate to refer back to the Python Playground for further experimentation!