លំហសិក្សាកម្ពុជា លំហសិក្សាកម្ពុជា V1.0
ចូល ចុះឈ្មោះ

Python Programming

មូលសង្ខេប / Abstract

This lesson introduces the basics of Python programming, including variables, data types, basic operations, and string manipulation. These concepts help beginners understand how to store, process, and work with data in Python.

ពាក្យគន្លឹះ

1. Variables

A variable is a name used to store value in a Python program. It allows us to save information and use it later. We create a variable by using assignment operator (=).

Example: x = 42

Here, x is the variable and 42 is its value. Variables are important because they help us store and work with data.

2. Variables and Their Types

Python can store different types of data in variables. The main types are:

  • Integer (int): whole numbers, such as x=10.
  • Float (float): decimal numbers, such as y=3.14.
  • String (str): text, such as "Hello".
  • Booleans (bool): either True or False.
  • Lists (list): a changeable collection, such as [1, 2, 3].
  • Tuples (tuple): a collection that cannot be changed, such as (4, 5).
  • Dictionarys (dict): stores information as key-value pairs.
  • Sets (set): stores unique values.
  • NoneType (None): shows that a variable has no value.

Python also distinguishes uppercase and lowercase letters, so Name and name are different variables.

3. Basic Operations

Python has several operations for working with data:

  • Arithmetic: +, -, *, /, //, %, and ** are used for calculations.
  • Assignment: = assigns a value, while +=, -=, *=, and /= can update a value.
  • Comparison: ==, !=, >, <, >=, and <= compare values and give True or False.
  • Logical: and, or, and not are used to work with conditions.
  • Membership: in and not in check whether a value exists in a sequence.

Example: 2 in [1, 2, 3] gives True.

4. String Manipulation

String manipulation means working with text in Python. We can join strings using +, find their length with len(), access characters using indexes, and select parts using slicing.

Python also provides methods such as .upper() and .lower() to change letter case, .strip() to remove extra spaces, .replace() to change text, and .split() to divide a string into parts. We can also use in to check whether a word or character exists in a string.

Ch01: Python-summary
PDF ឯកសារ
ទាញយក អាន
ចែករំលែក
រក្សាទុក
ការផ្សព្វផ្សាយ
ការផ្សព្វផ្សាយ
មតិយោបល់ 0
ចូលគណនី ដើម្បីបញ្ចេញមតិ