μ«μν
print(5)
print(-10)
print(3.14)
print(5+3)
print(2*8)
print(3*(3+1))
λ¬Έμν
print('νμ ')
print("λλΉ")
print("γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
γ
")
print("γ
"*9)
μλ£ν
print(5>10) #False
print(5<10) #True
print(True) #True
print(not True) #False
print(not(5>10)) #Ture
λ³μ
animal = "κ³ μμ΄"
name = "μ΅λ"
age = 8
hobby = "λ°₯"
is_adult = age >= 8
print("μ°λ¦¬μ§ " + animal + "μ μ΄λ¦μ " + name + "μμ")
print(name + "λ " + str(age) + "μ΄μ΄κ³ , " + hobby + "μ μμ£Ό μ’μν΄μ")
print(name + "λ μ΄λ₯ΈμΌκΉμ? " + str(is_adult))
# μ£Όμ
''' μ¬λ¬λ¬Έμ₯ '''
λ¬Έμ₯ μ ν + Ctrl + /
Quiz) λ³μλ₯Ό μ΄μ©ν΄ λ€μ λ¬Έμ₯μ μΆλ ₯νμμ€
λ³μλͺ
: station
λ³μκ° : "μ¬λΉ", "μ λλ¦Ό", "μΈμ²κ³΅ν" μμλλ‘ μ
λ ₯
μΆλ ₯ λ¬Έμ₯ : XXν μ΄μ°¨κ° λ€μ΄μ€κ³ μμ΅λλ€.
staion = "μ¬λΉ"
staion = "μ λλ¦Ό"
staion = "μΈμ²κ³΅ν"
print(staion + "ν μ΄μ°¨κ° λ€μ΄μ€κ³ μμ΅λλ€.")
μ°μ°μ
print(1+1)
print(3-2)
print(5*2)
print(6/3)
print(2**3) #8 μ κ³±κ° μΆλ ₯
print(5%3) #2 λλ¨Έμ§κ° μΆλ ₯
print(5//3) #1 λͺ« μΆλ ₯
print(10>3) #True
print(4>=7) #False
print(5<=5) #True
print(3==3) #True
print(4+3==7) #True
print(1!=3) #True
print(not(1!=3)) #False
print((3>0) and (3<5)) #Ture
print((3>0) & (3<5)) #True
print ((3>0) or (3<5)) #True
print ((3>0) | (3<5)) #True
print(5>4>3) #True
print(5>4>7) #False
μμ
print(2+3*4) #14
print((2+3)*4) #20
number = 2+3*4 #14
print(number) #14
number = number + 2
print(number) #16
number += 2
print(number) #18
number *= 2
print(number) #36
number /= 2
print(number) #18
number -= 2
print(number) #16
number %= 2
print(number) #0
μ«μ μ²λ¦¬ ν¨μ
print(abs(-5)) #5 μ λκ° μΆλ ₯
print(pow(4,2)) #16 4λ₯Ό 2λ² κ³±ν κ°
print(max(5,12)) #12 μ΅λκ° μΆλ ₯
print(min(5, 12)) #5 μ΅μκ° μΆλ ₯
print(round(3.14)) #3 λ°μ¬λ¦Όν κ° μΆλ ₯
print(round(4.99)) #5
from math import *
print(floor(4.99)) #4 floor : λ΄λ¦Ό
print(ceil(3.14)) #4 ceil : μ¬λ¦Ό
print(sqrt(16)) #4 sqrt : μ κ³±κ·Ό
λλ€ ν¨μ (λμ λ½κΈ°)
from random import *
print(random()) #μ€νν λλ§λ€ 0.0 ~ 1.0 λ―Έλ§μ μμμ κ° μμ±
print(random()*10) #0.0~10.0λ―Έλ§μ μμμ κ° μμ±
print(int(random()*10)) #0~10λ―Έλ§μ μμμ κ° μμ±
print(int(random()*10)+1) #1~10μ΄νμ μμμ κ° μμ±
print(int(random() * 45 ) +1) #1~45μ΄νμ μμμ κ° μμ±
print(randrange(1,46)) #1~45μ΄νμ μμμ κ° μμ±
print(randint(1, 45)) #1~45μ΄νμ μμμ κ° μμ±
Quiz 쑰건μ λ§λ μ€νλΌμΈ λͺ¨μ λ μ§λ₯Ό μ ν΄μ£Όλ νλ‘κ·Έλ¨ μμ±νκΈ°
쑰건1 : λλ€μΌλ‘ λ μ§ λ½μμΌν¨
쑰건2 : μ λ³ λ μ§λ λ€λ¦μ κ°μνμ¬ μ΅μ μΌμμΈ 28μΌ μ΄λ΄λ‘ μ€μ
쑰건3 : λ§€μ 1~3μΌμ μ μΈ
μΆλ ₯λ¬Έ μμ ) μ€νλΌμΈ μ€ν°λ λͺ¨μ λ μ§λ λ§€μ xμΌλ‘ μ μ λμμ΅λλ€.
from random import *
random = (randint(4,28))
print(random)
print("μ€νλΌμΈ μ€ν°λ λͺ¨μ λ μ§λ λ§€μ " + str(random) + "μΌλ‘ μ μ λμμ΅λλ€.")
λ¬Έμμ΄
sentence = 'λλ μλ
μ
λλ€'
print(sentence) #λλ μλ
μ
λλ€
sentence2 = "νμ΄μ¬μ μ¬μμ"
print(sentence2) #νμ΄μ¬μ μ¬μμ
sentence3 = """
λλ μλ
μ΄κ³ ,
νμ΄μ¬μ μ¬μμ
"""
print(sentence3)
#[error] SyntaxError: EOF while scanning triple-quoted string literal
μ¬λΌμ΄μ±
jumin = "990120-1234567"
print("μ±λ³ : " + jumin[7]) #1 index 0λΆν° μμ
print("μ° : " + jumin[0:2]) #99
print("μ : " + jumin[2:4]) #01
print("μΌ : " + jumin[4:6]) #20
print("μλ
μμΌ : " + jumin[:6]) #990120 0μμ΄ :6μΌλ‘ ννν΄λ λ¨
print("λ€ 7μ리 : " + jumin[7:]) #1234567 0μμ΄ 7:μΌλ‘ ννν΄λ λ¨
print("λ€ 7μ리 (λ€μμλΆν°) : " + jumin[-7:]) #1234567 맨 λ€μμ 7λ²μ§ΈκΉμ§
λ¬Έμμ΄ μ²λ¦¬ ν¨μ
python = "Python is easy"
print(python.lower()) #python is easy μ 체 μλ¬Έμλ‘ μΆλ ₯
print(python.upper()) #PYTHON IS EASY μ 체 λλ¬Έμλ‘ μΆλ ₯
print(python[0].isupper()) #Ture 첫 λ²μ§Έ κ°μ΄ λλ¬ΈμμΈμ§ νμΈ
print(len(python)) #14 μ 체 λ¬Έμμ΄ κΈΈμ΄ μΆλ ₯
print(python.replace("Python", "Java")) #Java is easy λ¨μ΄ κ΅μ²΄
index = python.index("n")
print(index) #5 λ¬Έμμ΄ nμ΄ λͺ λ²μ§Έ μμΉν΄μλμ§ μΆλ ₯
#index = python.index("n", index + 1) #6λ²μ§Έ λ¬Έμμ΄μμλΆν° nμ΄ λͺ λ²μ§Έ μμΉν΄μλμ§ μΆλ ₯
print(index)
print(python. find("n")) #μνλ κ° μμΌλ©΄ -1 λ°ν > νλ‘κ·Έλ¨ μ§ν
print(python. index("n")) #μνλ κ° μμΌλ©΄ error > νλ‘κ·Έλ¨ μ’
λ£
print(python.count("n")) #1 λ¬Έμμ΄nμ κ°μ
λ¬Έμμ΄ ν¬λ§·
print("a" + "b") #ab
print("a", "b") #a b
λ°©λ²1
print("λλ %dμ΄μ
λλ€." %20) #λλ 20μ΄μ
λλ€. d : μ μκ°
print("λλ %sμ μ’μν΄μ." %"νμ΄μ¬") #λλ νμ΄μ¬μ μ’μν΄μ. s : λ¬Έμμ΄
print("Appleμ %cλ‘ μμν΄μ." %"A") #Appleμ Aλ‘ μμν΄μ. c : ν κΈμ
%s
print("λλ %sμ΄μ
λλ€." %20) #λλ 20μ΄μ
λλ€.
μ¬λ¬ κ°
print("λλ %sμκ³Ό %sμμ μ’μν΄μ." %("νλ", "λΉ¨κ°")) #λλ νλμκ³Ό λΉ¨κ°μμ μ’μν΄μ.
λ°©λ²2
print("λλ {}μ΄μ
λλ€." .format(20)) #λλ 20μ΄μ
λλ€.
print("λλ {}μκ³Ό {}μμ μ’μν΄μ.".format("νλ", "λΉ¨κ°")) #λλ νλμκ³Ό λΉ¨κ°μμ μ’μν΄μ.
print("λλ {0}μκ³Ό {1}μμ μ’μν΄μ.".format("νλ", "λΉ¨κ°")) #λλ νλμκ³Ό λΉ¨κ°μμ μ’μν΄μ.
print("λλ {1}μκ³Ό {0}μμ μ’μν΄μ.".format("νλ", "λΉ¨κ°")) #λλ λΉ¨κ°μκ³Ό νλμμ μ’μν΄μ.
λ°©λ²3
print("λλ {age}μ΄μ΄λ©°, {color}μμ μ’μν΄μ.".format(age=20, color="λΉ¨κ°")) #λλ 20μ΄μ΄λ©°, λΉ¨κ°μμ μ’μν΄μ.
λ°©λ²4 (3.6.ver μ΄μ)
age = 20
color = "λΉ¨κ°"
print(f"λλ {age}μ΄μ΄λ©°, {color}μμ μ’μν΄μ.") #λλ 20μ΄μ΄λ©°, λΉ¨κ°μμ μ’μν΄μ.
νμΆ λ¬Έμ
print("λ°±λ¬Έμ΄ λΆμ¬μΌκ²¬
λ°±κ²¬μ΄ λΆμ¬μΌν") #error
print("λ°±λ¬Έμ΄ λΆμ¬μΌκ²¬ \n λ°±λ¬Έμ΄ λΆμ¬μΌν")
#λ°±λ¬Έμ΄ λΆμ¬μΌκ²¬
# λ°±λ¬Έμ΄ λΆμ¬μΌν
print("μ λ "μ΄λ΄"μ
λλ€.)") #error
print("μ λ 'μ΄λ΄'μ
λλ€.)") #μ λ 'μ΄λ΄'μ
λλ€.
print("μ λ \"μ΄λ΄\" μ
λλ€.") #μ λ "μ΄λ΄" μ
λλ€. \" \' : λ¬Έμ₯ λ΄μμ λ°μ΄νλ‘ μ΄μ©
\\ : λ¬Έμ₯ λ΄μμ \
print("C:\Users\KIM YOON\.spyder-py3") #error
print("C:\\Users\\KIM YOON\\.spyder-py3") #μ μ μΆλ ₯
\r : 컀μ 맨 μμΌλ‘ μ΄λ
print("Red apple\rPine") #Pineapple
\b : λ°±μ€νμ΄μ€ (ν κΈμ μμ )
print("Redd\bApple") #RedApple
\t : ν
print("Red\tApple") #Red Apple
Quiz) μ¬μ΄νΈλ³λ‘ λΉλ°λ²νΈλ₯Ό λ§λ€μ΄μ£Όλ νλ‘κ·Έλ¨μ μμ±νμμ€.
μ) http://naver.com
κ·μΉ1 : http:// λΆλΆμ μ μΈνκ³ μΆλ ₯
κ·μΉ2 : μ²μ λ§λλ μ (.) μ΄ν λΆλΆ μ μΈ
κ·μΉ3 : λ¨μ κΈμ μ€ μ²μ μΈμ리 + κΈμ κ°―μ + κΈμ λ΄ 'e'κ°μ + "!"λ‘ κ΅¬μ±
μ) μμ±λλ λΉλ°λ²νΈ : nav51!
pw = "http://naver.com"
print(pw)
pw = pw[7:-4]
print((pw[:3]),(pw.count("pw")),(print("\!")))
μ λ΅
pw = "http://naver.com"
pw = pw.replace("http://","")
print(pw) #naver.com
pw = pw[:pw.index(".")]
print(pw) #naver
pw = pw[:3] + str(len(pw)) + str(pw.count("e")) + "!"
print(pw) #nav60!
url = "http://youtube.com"
print("{0}μ λΉλ°λ²νΈλ {1}μ
λλ€.".format(url, pw))
μΆμ² : https://youtu.be/kWiCuklohdY [00:00:00~01:22:30]
'κ°μΈκ³΅λΆ > Python' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
43. Python μ μ΄λ¬Έ μ°μ΅λ¬Έμ (0) | 2021.11.03 |
---|---|
42. Python κΈ°λ³Έλ¬Έλ² μ°μ΅λ¬Έμ (0) | 2021.10.31 |
38. Python Basic3 (λ―ΈκΈ°μ¬) (0) | 2021.10.24 |
37. Python λ°λ³΅λ¬Έ μ°μ΅λ¬Έμ (0) | 2021.10.23 |
27. Python Basic2 (μλ£κ΅¬μ‘°, νλ¦μ μ΄) (0) | 2021.10.11 |