
π‘λ³μμ λͺ λͺ κ·μΉ
- λ³μ μ΄λ¦μλ λ€μ λ¬Έμλ§ μ¬μ© κ°λ₯νλ€: μλ¬Έμ(a - z), λλ¬Έμ(A - Z), μ«μ(0 - 9), μΈλλ°(_)
- λ³μλͺ μ λμλ¬Έμλ₯Ό ꡬλΆνλ€: apple, Apple, aPPleλ λͺ¨λ λ€λ₯Έ λ³μ
- λ³μλͺ μ μ«μλ‘ μμν μ μλ€. μλ¬Έμ, λλ¬Έμ, μΈλλ°λ‘λ§ μμν μ μλ€.
- μμ½μ΄λ λ³μλͺ μΌλ‘ μ¬μ©ν μ μλ€.
π³ λ³μμ μ μΈκ³Ό μ΄κΈ°ν(Assignment) => λμ ν λΉ
a = 10
b = True
c = 3.14
d = "Hello"
e = 'c'
f = {"name", "age", "email"}
print(type(a), type(b), type(c), type(d), type(e), type(f), sep='\n')
# <class 'int'>
# <class 'bool'>
# <class 'float'>
# <class 'str'>
# <class 'str'>
# <class 'set'>
del f #λ³μ μμ
a = 1; b = 2
a,b = b,a #λ³μ κ΅ν
print("λ³μ κ΅ν : a = %d, b = %d" % (a,b))
#λ³μ κ΅ν : a = 2, b = 1
a = (a = b + c) #error -> ν λΉλ¬Έμ΄ ν λΉλ¬Έμ ν¬ν¨ν μ μλ€.
π³ 1. type Number(int, float)
a = 10
b = 12.345
c = 0b0101 #2μ§μ
d = 0o12 #8μ§μ
e = 0x2d #16μ§μ
f = 123e2 #μ§μ νκΈ°λ²
g = 123E-2 #μ§μ νκΈ°λ²
print(a,b,c,d,e,f,g)
#10 12.345 5 10 45 12300.0 1.23
π³ λμ μμ±
h = random.random()*100 #0.0<=x<1.0
i = random.uniform(1, 100)
rand = int(random.random()*100)+1 #1~100 μμμ μ«μ
print(h)
print(int(i)) #λμλ₯Ό μ μλ‘ λ³ν
π³ μμΈ μ²λ¦¬
try:
x = float("a0.12")
except:
print("μ«μκ° μλ λ¬Έμμ΄μ΄ ν¬ν¨λμ΄ μμ΅λλ€.")
print(x)
π³ 볡μμ μλ£ν(complex)
y = 10 + complex(2)
print(y)
print(type(y)) #<class 'complex'>
π³ 2. type boolean :: bool
power = False #True, False
power = bool("") #False
power = bool(None) #False
power = bool(0) #False
power = bool(-10) #True
power = bool("LMH") #True
print(power)
print(type(power)) #<class 'bool'>
π³ 3. type string :: str
s = "Hello Python"
print(type(s)) #<class 'str'>
s1 = str(12345)
print(type(s1)) #<class 'str'>
print(s1+1) #error
π³ 4. type character :: chr
c = chr(48)
c = 'A'
c1 = 'hello' + 'world'
print(c) #A
print(type(c)) #<class 'str'>
print(c1) #helloworld
print(type(c1)) #<class 'str'>