លំហសិក្សាកម្ពុជា
V1.0
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:
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:
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.
មតិយោបល់ 0