๐ŸŒฑ → ๐ŸŒณ

[Python] ๊ธฐ์ดˆ ์ž๋ฃŒํ˜• ๋ณธ๋ฌธ

Server/Python

[Python] ๊ธฐ์ดˆ ์ž๋ฃŒํ˜•

BAY 2022. 5. 23. 13:14
728x90

1. print()

Point I
print() : ๋ฌธ์ž์—ด์„ ์ถœ๋ ฅํ•˜๋Š” ๋ช…๋ น์–ด

print("Hello Rabbit!")  

## ์ถœ๋ ฅ๊ฒฐ๊ณผ ##
Hello Rabbit!

Point II
์ฝค๋งˆ(,)๋ฅผ ํ†ตํ•ด ์—ฌ๋Ÿฌ ์ž๋ฃŒ๋ฅผ ์ถœ๋ ฅ

print(3, "Hello")   

## ์ถœ๋ ฅ๊ฒฐ๊ณผ ##
3 Hello

Point III
print()๋ฅผ ์—ฌ๋Ÿฌ ๋ฒˆ ์‚ฌ์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ ์ค„์— ๊ฑธ์ณ ์ถœ๋ ฅ

print(3)  
print(6)  
print(9)  

## ์ถœ๋ ฅ๊ฒฐ๊ณผ ##
3
6
9

2. ๊ธฐ๋ณธ ์ž๋ฃŒํ˜•

Point I
์ˆซ์žํ˜• : ์ˆซ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ์ž๋ฃŒํ˜•

3 : ์ •์ˆ˜  
3.14 : ์‹ค์ˆ˜  

Point II
๋ฌธ์ž์—ด : ๋ฌธ์ž, ํ˜น์€ ๋ฌธ์ž๋“ค์˜ ์ง‘ํ•ฉ - ํฐ๋”ฐ์˜ดํ‘œ(“)/์ž‘์€๋”ฐ์˜ดํ‘œ(‘)๋กœ ๊ตฌ๋ถ„

'Hello'  
'3.14'  
"3.14"  

Point III
๋ฆฌ์ŠคํŠธ : ์—ฌ๋Ÿฌ ์ž๋ฃŒ๋ฅผ ํ•จ๊ป˜ ๋ณด๊ด€ํ•˜๋Š” ์ž๋ฃŒํ˜• - ๋Œ€๊ด„ํ˜ธ([])๋กœ ๊ตฌ๋ถ„

[]  
['a', 'b']  
['a', 2]  

3. ๋ณ€์ˆ˜

Point I
๋ณ€์ˆ˜ : ์ž๋ฃŒ๋ฅผ ๋‹ด๋Š” ๊ทธ๋ฆ‡!
๋ณ€์ˆ˜ ์ด๋ฆ„ = ์ž๋ฃŒ ํ˜•ํƒœ๋กœ ์‚ฌ์šฉ

num = 10   
name = "Michael"   
grade = ['A+', 'B+', 'A0']  

Point II
๋ณ€์ˆ˜ ์ด๋ฆ„ ์ง“๊ธฐ
์ˆซ์ž, ์•ŒํŒŒ๋ฒณ, ์–ธ๋”๋ฐ”(_) ๋“ฑ์„ ์‚ฌ์šฉ

Point III
๊ธˆ์ง€ ๊ทœ์น™

  • ์ˆซ์ž๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ณ€์ˆ˜์ด๋ฆ„ ๊ธˆ์ง€
1st = 1000 #Error
  • ์ˆซ์ž๋กœ๋งŒ ๊ตฌ์„ฑ๋œ ๋ณ€์ˆ˜ ์ด๋ฆ„์€ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์–ด์š”
123 = "Hello!" #Error
  • ํŒŒ์ด์ฌ ๋ฌธ๋ฒ•์—์„œ ์ด๋ฏธ ์‚ฌ์šฉ๋˜๋Š” ๋‹จ์–ด(keyword, ์˜ˆ์•ฝ์–ด)๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์–ด์š”
for = 10 #Error
  • ๊ณต๋ฐฑ ๋ฌธ์ž( )์™€ ์—ฐ์‚ฐ์ž๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์–ด์š”
I am = "groot" #Error  
3+4 = 12 #Error

4. ์—ฐ์‚ฐ

Point I
์ˆซ์ž์˜ ์‚ฌ์น™์—ฐ์‚ฐ : +(๋”ํ•˜๊ธฐ), -(๋นผ๊ธฐ), *(๊ณฑํ•˜๊ธฐ), /(๋‚˜๋ˆ„๊ธฐ)

print(6+3) #9
print(6-3) #3
print(6*3) #18
print(6/3) #2.0

Point II
์ˆซ์ž์˜ ํŠน์ˆ˜์—ฐ์‚ฐ : **(์ œ๊ณฑ), //(๋ชซ ์—ฐ์‚ฐ), %(๋‚˜๋จธ์ง€ ์—ฐ์‚ฐ)

print(6**3) #216
print(6//3) #2
print(6%3) #0

Point III
๋ฌธ์ž์—ด์˜ ์—ฐ์‚ฐ: +(์—ฐ๊ฒฐํ•˜๊ธฐ), *(๋ฐ˜๋ณตํ•˜๊ธฐ)

print("Hello" + "World") #HelloWorld
print("Hello"*3) #HelloHelloHello

5. ์ธ๋ฑ์‹ฑ๊ณผ ์Šฌ๋ผ์ด์‹ฑ

Point I
์ธ๋ฑ์Šค : ๋ฌธ์ž์—ด๊ณผ ๋ฆฌ์ŠคํŠธ์˜ ํŠน์ • ์›์†Œ์˜ ์œ„์น˜, 0๋ถ€ํ„ฐ ์‹œ์ž‘!

"Hello"์—์„œ H = Index 0, e = index 1, ...

Point II
์ธ๋ฑ์‹ฑ : ๋ฌธ์ž์—ด๊ณผ ๋ฆฌ์ŠคํŠธ์˜ ํŠน์ • ์œ„์น˜(์ธ๋ฑ์Šค)์˜ ์›์†Œ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ

greet = "Hello!"  
print(greet[1])  

## ์ถœ๋ ฅ๊ฒฐ๊ณผ ##
e

Point III
์Šฌ๋ผ์ด์‹ฑ : ๋ฌธ์ž์—ด๊ณผ ๋ฆฌ์ŠคํŠธ์˜ ํŠน์ • ๋ถ€๋ถ„์„ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ

greet = "Hello!"  
print(greet[0:5])  
Hello
728x90