លំហសិក្សាកម្ពុជា
V1.0
By MoeunRithi Sreylompong
Store data values in memory.
Defined by: name, value, type, scope, mutability.
Created with = operator.
Python is dynamically typed → type inferred automatically.
Common types:
int → whole numbers
float → decimals
str → text
bool → True/False
list → [1,2,3] (mutable)
tuple → (1,2,3) (immutable)
dict → {"key":"value"}
set → {1,2,3}
Arithmetic: + - * / // % **
Assignment: = += -= *= /=
Comparison: == != > < >= <=
Logical: and or not
Membership: in, not in
Concatenation: "Hello" + "World" → "HelloWorld"
f‑strings: f"My name is {name}"
Length: len("Python") → 6
Indexing & slicing:
python
text = "Python"
text[0] # "P"
text[0:3] # "Pyt"
text[::-1] # "nohtyP"
Methods:
"hello".upper() → "HELLO"
"HELLO".lower() → "hello"
" hi ".strip() → "hi"
"Java".replace("Java","Python") → "Python"
Splitting: "This is a sentence".split() → ['This','is','a','sentence']
មតិយោបល់ 0