Notice
Recent Posts
Recent Comments
ยซ   2024/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Archives
Today
In Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

A Joyful AI Research Journey๐ŸŒณ๐Ÿ˜Š

[40] 230223 Ch. 3 ๋ผ์ฆˆ๋ฒ ๋ฆฌ ํŒŒ์ด๋ฅผ ์œ„ํ•œ ํŒŒ์ด์ฌ ๊ธฐ์ดˆ ๋ฐฐ์šฐ๊ธฐ: 1. ํŒŒ์ด์ฌ ์‹œ์ž‘ํ•˜๊ธฐ, 2. ํŒŒ์ด์ฌ ์ž๋ฃŒํ˜• [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 40์ผ] ๋ณธ๋ฌธ

๐ŸŒณBootcamp Revision 2023โœจ/Python, Flask, SQL

[40] 230223 Ch. 3 ๋ผ์ฆˆ๋ฒ ๋ฆฌ ํŒŒ์ด๋ฅผ ์œ„ํ•œ ํŒŒ์ด์ฌ ๊ธฐ์ดˆ ๋ฐฐ์šฐ๊ธฐ: 1. ํŒŒ์ด์ฌ ์‹œ์ž‘ํ•˜๊ธฐ, 2. ํŒŒ์ด์ฌ ์ž๋ฃŒํ˜• [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 40์ผ]

yjyuwisely 2023. 2. 23. 16:42

230223 Thu 40th class

Ch. 3 ๋ผ์ฆˆ๋ฒ ๋ฆฌ ํŒŒ์ด๋ฅผ ์œ„ํ•œ ํŒŒ์ด์ฌ ๊ธฐ์ดˆ ๋ฐฐ์šฐ๊ธฐ
์ง„๋„: p. 82 ~ (๊ต์žฌ: IoT ์‚ฌ๋ฌผ์ธํ„ฐ๋„ท์„ ์œ„ํ•œ ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด 4 ์ •์„, ์ €์ž: ์ตœ์ฃผํ˜ธ , ๊น€์žฌ๋ฒ” , ์ •๋™์ง„)
์ฐธ๊ณ  ๊ฐ€๋Šฅ ์ฑ…: ์™•์ดˆ๋ณด๋ฅผ ์œ„ํ•œ Python: ์‰ฝ๊ฒŒ ํ’€์–ด ์“ด ๊ธฐ์ดˆ ๋ฌธ๋ฒ•๊ณผ ์‹ค์Šต

๊ต์žฌ ์ฝ”๋“œ ๊นƒํ—ˆ๋ธŒ: https://github.com/codingspecialist/RaspberryPi4-Book-Example

๊ต์žฌ ์†Œ์Šค ๋ฐ PPT: http://jspstudy.co.kr/main/main.jsp
์ €์ž ์นดํŽ˜: https://cafe.naver.com/metacoding

 

IoT ์‚ฌ๋ฌผ์ธํ„ฐ๋„ท์„ ์œ„ํ•œ ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด 4 ์ •์„ | ์ตœ์ฃผํ˜ธ - ๊ต๋ณด๋ฌธ๊ณ 

IoT ์‚ฌ๋ฌผ์ธํ„ฐ๋„ท์„ ์œ„ํ•œ ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด 4 ์ •์„ | ใ€ŽIoT ์‚ฌ๋ฌผ์ธํ„ฐ๋„ท์„ ์œ„ํ•œ ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด 4 ์ •์„ใ€์€ ์™•์ดˆ๋ณด๋„ ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด๋ฅผ ์ด์šฉํ•ด ๋‹ค์–‘ํ•œ IoT๋ฅผ ์ง์ ‘ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๋„๋ก ์ „๊ธฐ์ „์ž ๊ธฐ์ดˆ ์›๋ฆฌ๋ถ€ํ„ฐ ์„ผ

product.kyobobook.co.kr

์˜ค๋Š˜ ๋ฐฐ์šด ๊ฒƒ ์ค‘ ๊ธฐ์–ตํ•  ๊ฒƒ์„ ์ •๋ฆฌํ–ˆ๋‹ค.


๋‚ด๊ฐ€ ๋ชฐ๋ž๋˜ ๊ฒƒ 

1. ๋ฆฌ์ŠคํŠธ ์ž๋ฃŒํ˜•: [,] ๋Œ€๊ด„ํ˜ธ๋ฅผ ์—ด๊ณ  ๋‹ซ๋Š”๋‹ค. ๋ฐฐ์—ด๊ณผ ํก์‚ฌํ•œ ๊ฐœ๋…์ด๋‹ค.

[0,0,0,0]
[1, 2, 3]
li = [10,"์žฅ๋™๊ฑด",23,"์„œ์šธ]
li 10 ์žฅ๋™๊ฑด 23 ์„œ์šธ
  li[0] li[1] li[2] li[3]


2. ํŠœํ”Œ ์ž๋ฃŒํ˜•: (,) ์†Œ๊ด„ํ˜ธ๋กœ ์—ด๊ณ  ๋‹ซ๋Š”๋‹ค. ๊ด„ํ˜ธ๋Š” ์ƒ๋žต ๊ฐ€๋Šฅํ•˜๋‹ค. 
ํŠœํ”Œ์€ ํ•œ ๋ฒˆ ๊ฐ’์„ ์ •ํ•˜๋ฉด ๋‚ด๋ถ€์˜ ๊ฐ’์„ ๋ฐ”๊ฟ€ ์ˆ˜๊ฐ€ ์—†๋‹ค.
์ฝ๊ธฐ ์ „์šฉ
์ด๋‹ค.

 ('red', 4, 'python', True)
 (1, 2, 3)
 tu = (10, "์žฅ๋™๊ฑด", 23, "์„œ์šธ")
tu 10 ์žฅ๋™๊ฑด 23 ์„œ์šธ
  tu[0] tu[1] tu[2] tu[3]


3. ๋”•์…”๋„ˆ๋ฆฌ ์ž๋ฃŒํ˜•: {,} ์ค‘๊ด„ํ˜ธ๋กœ ์—ด๊ณ  ๋‹ซ๋Š”๋‹ค.

{dict = ["๋ฒˆํ˜ธ":10, "์„ฑ๋ช…": "์žฅ๋™๊ฑด", "๋‚˜์ด":23, "์‚ฌ๋Š”๊ณณ":"์„œ์šธ"}
dict["์‚ฌ๋Š”๊ณณ"] = "๊ฒฝ๊ธฐ๋„"
dic (value) 10 ์žฅ๋™๊ฑด 23 ์„œ์šธ
(key) dic[๋ฒˆํ˜ธ] dic[์„ฑ๋ช…] dic[๋‚˜์ด] dic[์‚ฌ๋Š”๊ณณ]

append๋Š” ์ œ์ผ ๋งˆ์ง€๋ง‰์— ๊ฐ’์„ ์ถ”๊ฐ€ํ•œ๋‹ค.

aa.append(40)


insert๋Š” ๋‚ด๊ฐ€ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ์€ ๊ณณ์— ์ถ”๊ฐ€ํ•œ๋‹ค.

aa.insert(2, 222)

 

์ž๋ฃŒํ˜•

Java
HashMap(ํ•ด์‰ฌ๋งต): Java HashMap is a class which is used to perform operations such as inserting, deleting and locating elements in a map. We create a map, where we pass two kinds of values which are 'key' and 'value'.

Javascript/jQuery
JSON(์ œ์ด์Šจ): JSON is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays.

Python
Dictionary(๋”•์…”๋„ˆ๋ฆฌ): Dictionaries are used to store data values in key:value pairs. A dictionary is a collection which is ordered, changeable and do not allow duplicates.

ํŒŒ์ด์ฌ ๋ฐฐ์—ด ํŠน์ • ์š”์†Œ ์‚ญ์ œ
์ฐธ๊ณ : https://www.lainyzine.com/ko/article/how-to-delete-elements-of-a-list-in-python/


Ch. 3 ๋ผ์ฆˆ๋ฒ ๋ฆฌ ํŒŒ์ด๋ฅผ ์œ„ํ•œ ํŒŒ์ด์ฌ ๊ธฐ์ดˆ ๋ฐฐ์šฐ๊ธฐ

์ฑ…์˜ ๋ชฉ์ฐจ
01 _ ํŒŒ์ด์ฌ ์‹œ์ž‘ํ•˜๊ธฐ
01-1 ํŒŒ์ด์ฌ ๊ฐœ์š”
01-2 ํŒŒ์ด์ฌ Windows ์„ค์น˜ํ•˜๊ธฐ
01-3 ํŒŒ์ด์ฌ์˜ ์ฃผ์„

02 _ ํŒŒ์ด์ฌ ์ž๋ฃŒํ˜•
02-1 ์ˆซ์žํ˜•
02-2 ๋ฌธ์žํ˜•
02-3 ๋ฆฌ์ŠคํŠธ
02-4 ํŠœํ”Œ
02-5 ๋”•์…”๋„ˆ๋ฆฌ

03 _ ํŒŒ์ด์ฌ ์ œ์–ด๋ฌธ

03-1 if๋ฌธ
03-2 for๋ฌธ
03-3 whie๋ฌธ
03-4 break๋ฌธ

04 _ ํŒŒ์ด์ฌ ํ•จ์ˆ˜ ์‚ฌ์šฉ๋ฒ•

04-1 ํ•จ์ˆ˜ ์„ ์–ธํ•˜๊ธฐ
04-2 ํ•จ์ˆ˜ ์ธ์ˆ˜ ์‚ฌ์šฉํ•˜๊ธฐ

05 _ ํŒŒ์ด์ฌ ํด๋ž˜์Šค์™€ ๋ชจ๋“ˆ

05-1 ํด๋ž˜์Šค
05-2 ๋ชจ๋“ˆ
05-3 ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

1. ํŒŒ์ด์ฌ ์‹œ์ž‘ํ•˜๊ธฐ

1.1 ํŒŒ์ด์ฌ ๊ฐœ์š”

//Javascript or Java
if (์กฐ๊ฑด์‹){
	์ฐธ์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ
}else{
	๊ฑฐ์ง“์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ
}
//Python
if ์กฐ๊ฑด์‹:
	์ฐธ์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ1
    ์ฐธ์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ2
else:
	๊ฑฐ์ง“์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ1
    ๊ฑฐ์ง“์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ2

๋“ค์—ฌ์“ฐ๊ธฐ๊ฐ€ ์ค‘์š”ํ•˜๋‹ค. 
ํƒญ(Tab) ๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์„ ๊ฒƒ์„ ๋งค์šฐ ๊ฐ•๋ ฅํžˆ ์š”๊ตฌํ•œ๋‹ค. 

1.2 ํŒŒ์ด์ฌ Windows ์„ค์น˜ํ•˜๊ธฐ

ํŒŒ์ด์ฌ ์„ค์น˜ํ•  ๋•Œ ํ™˜๊ฒฝ ์„ค์ • ์ฒดํฌ ํ•˜๊ธฐ

1.3 ํŒŒ์ด์ฌ์˜ ์ฃผ์„

#ํ•œ ์ค„ ์ฃผ์„

''' 

์—ฌ๋Ÿฌ์ค„ ์ฃผ์„

'''

"""

์—ฌ๋Ÿฌ์ค„ ์ฃผ์„

"""

๋ฐ˜๋ฉด, ์•„๋ž˜๋Š” ์ž๋ฐ”์˜ ์ฃผ์„์ด๋‹ค.

//
/*


*/

2. ํŒŒ์ด์ฌ ์ž๋ฃŒํ˜•

์ž๋ฐ”  ํŒŒ์ด์ฌ ์ž๋ฃŒํ˜•
[1] ๊ธฐ๋ณธํ˜• Primitive Type
1.1) ์ˆซ์žํ˜•
byte a = 10;
int b = 20;
double c = 3.14;

1.2) ๋ฌธ์ž์—ดํ˜•
1.3) ๋…ผ๋ฆฌํ˜•

[2] ์ฐธ์กฐํ˜• Reference Type
1) ์ˆซ์žํ˜•
a = 10
b = 20
c = 3.14

2) ๋ฌธ์ž์—ด ์ž๋ฃŒํ˜•

3) ๋ฆฌ์ŠคํŠธ ์ž๋ฃŒํ˜• 
4) ํŠœํ”Œ ์ž๋ฃŒํ˜• 
5) ๋”•์…”๋„ˆ๋ฆฌ ์ž๋ฃŒํ˜• 

์ธํ„ฐํ”„๋ฆฌํ„ฐ: ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์˜ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ๋ฐ”๋กœ ์‹คํ–‰ํ•˜๋Š” ์ปดํ“จํ„ฐ ํ”„๋กœ๊ทธ๋žจ ๋˜๋Š” ํ™˜๊ฒฝ ex) Python, Javascript
์ปดํŒŒ์ผ๋Ÿฌ: ์›์‹œ ์ฝ”๋“œ๋ฅผ ๊ธฐ๊ณ„์–ด๋กœ ๋ฒˆ์—ญํ•œ๋‹ค. ex) Java

ํŒŒ์ด์ฌ ์ž๋ฃŒํ˜•

  • Numeric Types: int(์ •์ˆ˜), float(์†Œ์ˆ˜), complex(๋ณต์†Œ์ˆ˜)
  • Sequence Types: str(๋ฌธ์ž์—ด), list(๋ฆฌ์ŠคํŠธ), tuple(ํŠœํ”Œ)
  • Mapping Type: dict(๋”•์…”๋„ˆ๋ฆฌ)
  • Set Types: set(์ง‘ํ•ฉ)
  • Boolean Type: bool(๋ถˆ๋ฆฌ์–ธ)
  • Binary Types: bytes, bytearray, memoryview

์ฐธ๊ณ : https://velog.io/@jewon119/01.-Python-%EA%B8%B0%EC%B4%88-%EB%8D%B0%EC%9D%B4%ED%84%B0-%ED%83%80%EC%9E%85data-type


Java์˜ ๋ฐ์ดํ„ฐ ์œ ํ˜•์€ 8์ข…๋ฅ˜์˜ ๊ธฐ๋ณธํ˜•(primitive type)๊ณผ ์ฐธ์กฐํ˜•(reference type)์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

  • Java Data Type
    • Primitive Type
      • Boolean Type(boolean)
      • Numeric Type
        • Integral Type
          • Integer Type(short, int, long)
          • Floating Point Type(float, double)
        • Character Type(char)
    • Reference Type
      • Class Type
        • String Type
        • Wrapper Class
      • Interface Type
      • Array Type
      • Enum Type

์ฐธ๊ณ : https://www.devkuma.com/docs/java/data-type/


2.1 ์ˆซ์žํ˜•

์ •์ˆ˜ ๋ฐ ์‹ค์ˆ˜๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ํƒ€์ž…์ด๋‹ค.
์ˆซ์žํ˜• ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ์ถœ๋ ฅํ•˜๋Š” ์˜ˆ์ œ์ด๋‹ค. 

a = 123 # ๋ณ€์ˆ˜ ์„ ์–ธ๊ณผ ๋™์‹œ์— ์ดˆ๊ธฐํ™”
print(a)
print(type(a))

์ž๋ฐ”๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

//Java
class A{
	public static void main(String[] args){
    	int a = 123;
        System.out.println(a);
	}
}

์˜ˆ์ œ 1) 

a = 123 # ๋ณ€์ˆ˜ ์„ ์–ธ๊ณผ ๋™์‹œ์— ์ดˆ๊ธฐํ™”
print(a)
print(type(a)) # type ํ•จ์ˆ˜๋Š” ๋ณ€์ˆ˜์˜ ํƒ€์ž…์„ ๋ฆฌํ„ด

a = 100 * 100
print(a)

a , b = 9 , 2
print(a*b)

์ž๋ฐ”๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค. 

//Java
class A{
	public static void main(String[] args){
    	int a, b;
        a = 9;
        b = 2;
        System.out.println(a*b);
	}
}

๊ฒฐ๊ณผ)

123
<class 'int'>
10000
18

2.2 ๋ฌธ์žํ˜•

๋ฌธ์ž์—ด์„ ํ‘œํ˜„ํ•˜๋Š” ํƒ€์ž…์ด๋‹ค. 

์˜ˆ์ œ)

a = "ํŒŒ์ด์ฌ ๋งŒ์„ธ" #์Œ ๋”ฐ์˜ดํ‘œ๋กœ ๋ฌธ์ž์—ด ๊ฐ’์„ ์„ ์–ธ
print(a)
print(type(a)) #type ํ•จ์ˆ˜๋Š” ๋ณ€์ˆ˜์˜ ํƒ€์ž…์„ ๋ฆฌํ„ด
b = 'python go' #ํ™‘ ๋”ฐ์˜ดํ‘œ๋กœ ๋ฌธ์ž์—ด ๊ฐ’์„ ์„ ์–ธ
print(b)

๊ฒฐ๊ณผ)

ํŒŒ์ด์ฌ ๋งŒ์„ธ
<class 'str'>
python go

๋ฌธ์ œ ํ’€์–ด๋ณด๊ธฐ)

Q1. type()ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์•„๋ž˜ ๋ณ€์ˆ˜์— ๋ฐ”์ธ๋”ฉ๋œ ๊ฐ’์˜ ํƒ€์ž…์„ ํŒ๋ณ„ํ•˜๊ธฐ.
a = "132"
์˜ˆ์‹œ)

a = "132"
#type(์ž๋ฃŒํ˜•)
print(type(a))

๊ฒฐ๊ณผ)

<class 'str'>

 

Q2. ๋ณ€์ˆ˜ s์™€ t์—๋Š” ๊ฐ๊ฐ ๋ฌธ์ž์—ด์ด ๋ฐ”์ธ๋”ฉ ๋˜์–ด์žˆ๋‹ค.
s = "hello"
t = "python"

๋‘ ๋ณ€์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์•„๋ž˜์™€ ๊ฐ™์ด ์ถœ๋ ฅํ•ด๋ณด๊ธฐ

์‹คํ–‰ ์˜ˆ:
hello! python

์ •๋‹ต)

s = "hello"
t = "python"
print(s + "! " + t)

๊ฒฐ๊ณผ)

hello! python

Q3. ์•„๋ž˜ ์ฝ”๋“œ์˜ ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ์˜ˆ์ƒํ•˜๊ธฐ
a = "3"
b = "4"
print(a + b)
print("Hi" * 3)

์˜ˆ์ œ)

a = "3"
b = "4"
print(a+b) #๋‚ด ์˜ˆ์ƒ์€ 34
print("Hi" * 3) #๋‚ด ์˜ˆ์ƒ์€ HiHiHi

๊ฒฐ๊ณผ)

34
HiHiHi

Q4. ํ™”๋ฉด์— '-'๋ฅผ 80๊ฐœ ์ถœ๋ ฅํ•˜๊ธฐ

์˜ˆ์ œ)

print("-"*80)

๊ฒฐ๊ณผ)

--------------------------------------------------------------------------------

Q5. ๋ณ€์ˆ˜์— ๋‹ค์Œ ๋ฌธ์ž์—ด์ด ๋ฐ”์ธ๋”ฉ๋˜์–ด ์žˆ๋‹ค.
t1 = 'python'
t2 = 'java'
๋ณ€์ˆ˜์— ๋ฌธ์ž์—ด ๋”ํ•˜๊ธฐ์™€ ๋ฌธ์ž์—ด ๊ณฑํ•˜๊ธฐ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์•„๋ž˜์ฒ˜๋Ÿผ ์ถœ๋ ฅํ•˜๊ธฐ

์‹คํ–‰ ์˜ˆ:
python java python java python java python java 

์˜ˆ์ œ)

t1 = "python"
t2 = "java"
print((t1 + " " + t2 + " ")*4)

๊ฒฐ๊ณผ)

python java python java python java python java

2.3 ๋ฆฌ์ŠคํŠธ p. 88

๋ฆฌ์ŠคํŠธ๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ฐ’๋“ค์„ ํ•˜๋‚˜์˜ ๋ณ€์ˆ˜๋กœ ๋ฌถ์–ด์„œ ์‚ฌ์šฉํ•˜๋Š” ํƒ€์ž…์ด๋‹ค. ์š”์†Œ์˜ ๊ฐ’๋“ค์€ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•˜๋‹ค.

[,] ๋Œ€๊ด„ํ˜ธ๋ฅผ ์—ด๊ณ  ๋‹ซ๋Š”๋‹ค. ๋ฐฐ์—ด๊ณผ ํก์‚ฌํ•œ ๊ฐœ๋…์ด๋‹ค.
[0,0,0,0]์ฒ˜๋Ÿผ ๋Œ€๊ด„ํ˜ธ๋ฅผ ์—ด๊ณ  ๋‹ซ์œผ๋ฉด ๋ฆฌ์ŠคํŠธ ์ž๋ฃŒํ˜•์ด๋‹ค. 

[0,0,0,0]
[1, 2, 3]
li = [10,"์žฅ๋™๊ฑด",23,"์„œ์šธ]
li 10 ์žฅ๋™๊ฑด 23 ์„œ์šธ
  li[0] li[1] li[2] li[3]


(,) ์†Œ๊ด„ํ˜ธ๋Š” ํŠœํ”Œ ์ž๋ฃŒํ˜•์ด๋‹ค. ex. ('red', 4, 'python', True)
{,} ์ค‘๊ด„ํ˜ธ๋Š” ๋”•์…”๋„ˆ๋ฆฌ ์ž๋ฃŒํ˜•์ด๋‹ค. ex. {dict = ['๋ฒˆํ˜ธ':10, '์„ฑ๋ช…': '์žฅ๋™๊ฑด', '๋‚˜์ด':23, '์‚ฌ๋Š”๊ณณ':'์„œ์šธ'}


์˜ˆ์ œ 1) ๋ฆฌ์ŠคํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์ˆซ์žํ˜• ๋ณ€์ˆ˜ 4๊ฐœ๋ฅผ ์„ ์–ธํ•˜์—ฌ ์ž…๋ ฅ ๋ฐ›์€ ๊ฐ’๋“ค์˜ ํ•ฉ์„ ์ถœ๋ ฅํ•œ๋‹ค. 
Python์˜ input์€ Java์˜ Scanner์™€ ๊ฐ™๋‹ค. 

a, b, c, d = 0, 0, 0, 0
hap = 0
a = int(input("1๋ฒˆ์งธ ์ˆซ์ž : ")) #์ˆซ์ž๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ a์— ๊ทธ ๊ฐ’์„ ๋Œ€๋น„
b = int(input("2๋ฒˆ์งธ ์ˆซ์ž : ")) 
c = int(input("3๋ฒˆ์งธ ์ˆซ์ž : ")) 
d = int(input("4๋ฒˆ์งธ ์ˆซ์ž : ")) 
hap = a + b + c + d
print("ํ•ฉ๊ณ„ => %d" % hap) #%d์—๋Š” % ๋’ค์— ์„ ์–ธํ•œ hap๊ฐ’์ด ๋Œ€์ž…

์•„๋ž˜๋Š” ์ž๋ฐ”์˜ ์˜ˆ์‹œ์ด๋‹ค. 

//Java
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int hap = 0;
System.out.println("1๋ฒˆ์งธ ์ˆซ์ž: ");
int a = Integer.parseInt(s.next()); //ํ‚ค๋ณด๋“œ๋กœ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. 
System.out.println("2๋ฒˆ์งธ ์ˆซ์ž: ");
int b = Integer.parseInt(s.next());
System.out.println("3๋ฒˆ์งธ ์ˆซ์ž: ");
int c = Integer.parseInt(s.next());
System.out.println("4๋ฒˆ์งธ ์ˆซ์ž: ");
int d = Integer.parseInt(s.next());

hap = a + b + c + d;
System.out.println("ํ•ฉ๊ณ„ ==> %d", hap)

๊ฒฐ๊ณผ)

1๋ฒˆ์งธ ์ˆซ์ž : 10
2๋ฒˆ์งธ ์ˆซ์ž : 20
3๋ฒˆ์งธ ์ˆซ์ž : 30
4๋ฒˆ์งธ ์ˆซ์ž : 40
ํ•ฉ๊ณ„ => 100

์˜ˆ์ œ 2) ๋ฆฌ์ŠคํŠธ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜์—ฌ ์˜ˆ์ œ 1๊ณผ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ๋งŒ๋“ค์–ด๋ณธ๋‹ค. 
[0,0,0,0]์ฒ˜๋Ÿผ ๋Œ€๊ด„ํ˜ธ๋ฅผ ์—ด๊ณ  ๋‹ซ์œผ๋ฉด ๋ฆฌ์ŠคํŠธ ์ž๋ฃŒํ˜•์ด๋‹ค. 

aa = [0, 0, 0, 0] #์ˆซ์ž 4๊ฐœ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฆฌ์ŠคํŠธ ๋ณ€์ˆ˜
hap = 0
aa[0] = int(input("1๋ฒˆ์งธ ์ˆซ์ž : ")) #์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ์ˆซ์ž๋ฅผ ๋ฆฌ์ŠคํŠธ์˜ ์ฒซ ๋ฒˆ์งธ ์š”์†Œ์— ๋Œ€์ž…
aa[1] = int(input("2๋ฒˆ์งธ ์ˆซ์ž : ")) 
aa[2] = int(input("3๋ฒˆ์งธ ์ˆซ์ž : ")) 
aa[3] = int(input("4๋ฒˆ์งธ ์ˆซ์ž : ")) 
hap = aa[0] + aa[1] + aa[2] + aa[3]
print("ํ•ฉ๊ณ„2 => %d" % hap) #์ž…๋ ฅ๋ฐ›์€ 4๊ฐœ์˜ ๊ฐ’๋“ค์„ ํ•ฉ์ณ์„œ ์ฝ˜์†”์ฐฝ์— ์ถœ๋ ฅ

๊ฒฐ๊ณผ)

1๋ฒˆ์งธ ์ˆซ์ž : 1
2๋ฒˆ์งธ ์ˆซ์ž : 2
3๋ฒˆ์งธ ์ˆซ์ž : 3
4๋ฒˆ์งธ ์ˆซ์ž : 4
ํ•ฉ๊ณ„2 => 10

์˜ˆ์ œ 3) ๋ฆฌ์ŠคํŠธ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๊ณ ์ •๋œ ์š”์†Œ์˜ ๊ฐœ์ˆ˜๊ฐ€ ์•„๋‹Œ ์œ ๋™์ ์ธ ์š”์†Œ๊ฐ€ ๋งŒ๋“ค์–ด์ง„๋‹ค. 
len
= ํŒŒ์ด์ฌ์—์„œ ๋ฆฌ์ŠคํŠธ์˜ ๊ธธ์ด (๋ฐ˜๋ฉด ์ž๋ฐ”๋Š” length)

aa = []
aa.append(0) #๋ฐฐ์—ด์— ์ถ”๊ฐ€ํ•œ๋‹ค. 
aa.append(0)
aa.append(0)
aa.append(0)
print(len(aa)) #๋ฐฐ์—ด์˜ ๊ธธ์ด
print(aa)
bb = []
for i in range(0, 100):
    bb.append(i)
print(bb)

๊ฒฐ๊ณผ)

4
[0, 0, 0, 0]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]

์ž๋ฐ”์˜ ๋ฐฐ์—ด์€ ํŒŒ์ด์ฌ์˜ ๋ฆฌ์ŠคํŠธ์™€ ๊ฐ™๋‹ค. 
ํŒŒ์ด์ฌ์€ [,]๊ฐ€ ๋ฆฌ์ŠคํŠธ ํƒ€์ž…์ด๋‹ค. 

//java
//๋ณ€์ˆ˜
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int hap = a + b + c + d;

//๋ฐฐ์—ด
int[] a = {0,0,0,0}
int hap = a[0] + a[1] + a[2] + a[3]

์˜ˆ์ œ 4) ๋ฆฌ์ŠคํŠธ์—์„œ ์š”์†Œ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•œ ๋‹ค์–‘ํ•œ ์œ„์น˜ ๊ฐ’(index ๊ฐ’)์„ ์ ์šฉํ•œ๋‹ค. 
ํŒŒ์ด์ฌ์˜ ๋ฆฌ์ŠคํŠธ ์ž๋ฃŒํ˜•์€ ์ž๋ฐ”์˜ ๋ฐฐ์—ด์ฒ˜๋Ÿผ ์ €์žฅ์ด ๋œ๋‹ค. 

aa[-1]: ๋งˆ์ง€๋ง‰ ๊ฐ’
aa[-2]: ๋งˆ์ง€๋ง‰์—์„œ ์•ž์˜ ๊ฐ’

์ฐธ๊ณ : https://dojang.io/mod/page/view.php?id=1311

aa = [10, 20, 30, 40] #๋ฆฌ์ŠคํŠธ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธ
print("aa[-1]์€ %d, aa[-2]๋Š” %d" % (aa[-1], aa[-2])) 
# % ๋’ค์— ์žˆ๋Š” aa[-1]์€ ์ฒซ๋ฒˆ์งธ %d aa[-2]๋Š” ๋‘ ๋ฒˆ์งธ %d์— ๋Œ€์ž…
print(aa[0:2]) #aa ๋ฆฌ์ŠคํŠธ์˜ ์ฒซ ๋ฒˆ์งธ๋ถ€ํ„ฐ ๋‘ ๋ฒˆ์งธ ์š”์†Œ ๊ฐ’์„ ์ถœ๋ ฅ
print(aa[2:4]) #aa ๋ฆฌ์ŠคํŠธ์˜ ์„ธ ๋ฒˆ์งธ๋ถ€ํ„ฐ ๋„ค ๋ฒˆ์งธ ์š”์†Œ ๊ฐ’์„ ์ถœ๋ ฅ
print(aa[0:]) #aa ๋ฆฌ์ŠคํŠธ์˜ ์ฒซ ๋ฒˆ์งธ๋ถ€ํ„ฐ ๋๊นŒ์ง€ ์š”์†Œ ๊ฐ’์„ ์ถœ๋ ฅ

๊ฒฐ๊ณผ)

aa[-1]์€ 40, aa[-2]๋Š” 30
[10, 20]
[30, 40]
[10, 20, 30, 40]

์˜ˆ์ œ 5) ๋ฆฌ์ŠคํŠธ์—์„œ ๋‹ค์–‘ํ•˜๊ฒŒ ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ๋Š” ํ•จ์ˆ˜๋ฅผ ์ ์šฉํ•œ๋‹ค.  p. 90

extend ํ™•์žฅ์‹œํ‚ค๋‹ค (์ž๋ฐ”์˜ ์ƒ์†๊ณผ๋Š” ๋‹ค๋ฆ„)
aa.append(40): append๋Š” ์ œ์ผ ๋งˆ์ง€๋ง‰์— ๊ฐ’์„ ์ถ”๊ฐ€ํ•œ๋‹ค. 
aa.insert(2, 222): insert๋Š” ๋‚ด๊ฐ€ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ์€ ๊ณณ์— ์ถ”๊ฐ€ํ•œ๋‹ค. 

์ฐธ๊ณ 

aa = [30, 10, 20]
print("ํ˜„์žฌ์˜ ๋ฆฌ์ŠคํŠธ: %s" %aa)

aa.append(40) #์š”์†Œ๋ฅผ ํ•˜๋‚˜ ์ถ”๊ฐ€
print("append ํ›„์˜ ๋ฆฌ์ŠคํŠธ: %s" %aa)
aa.pop() #aa ๋ฆฌ์ŠคํŠธ์˜ ์ œ์ผ ๋งˆ์ง€๋ง‰ ์š”์†Œ๋ฅผ ๋บ€๋‹ค.
print("pop ํ›„์˜ ๋ฆฌ์ŠคํŠธ: %s" %aa)
aa.sort() #๋ฆฌ์ŠคํŠธ ์š”์†Œ ๊ฐ’๋“ค์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ
print("sort ํ›„์˜ ๋ฆฌ์ŠคํŠธ: %s" %aa)
aa.reverse() #๋ฆฌ์ŠคํŠธ ์š”์†Œ ๊ฐ’๋“ค์„ ์—ญ์ˆœ์œผ๋กœ ์ •๋ ฌ
print("reverse ํ›„์˜ ๋ฆฌ์ŠคํŠธ: %s" %aa)
aa.insert(2, 222) #aa ๋ฆฌ์ŠคํŠธ์— ์„ธ ๋ฒˆ์งธ ์œ„์น˜์— 222๊ฐ’์„ ์ถ”๊ฐ€
print("insert(2, 222) ํ›„์˜ ๋ฆฌ์ŠคํŠธ: %s" %aa)
print("20๊ฐ’์˜ ์œ„์น˜: %d" %aa.index(20))
aa.remove(222) #222 ์š”์†Œ ๊ฐ’์„ ๋ฆฌ์ŠคํŠธ์—์„œ ์‚ญ์ œ
print("remove(222) ํ›„์˜ ๋ฆฌ์ŠคํŠธ: %s" %aa)
aa.extend([77,88,77]) #๋‹ค๋ฅธ ๋ฆฌ์ŠคํŠธ๋ฅผ ํ™•์žฅ
print("extend([77,88,77]) ํ›„์˜ ๋ฆฌ์ŠคํŠธ: %s" %aa)
print("77๊ฐ’์˜ ๊ฐœ์ˆ˜: %d" % aa.count(77))

๊ฒฐ๊ณผ)

ํ˜„์žฌ์˜ ๋ฆฌ์ŠคํŠธ: [30, 10, 20]
append ํ›„์˜ ๋ฆฌ์ŠคํŠธ: [30, 10, 20, 40]
pop ํ›„์˜ ๋ฆฌ์ŠคํŠธ: [30, 10, 20]
sort ํ›„์˜ ๋ฆฌ์ŠคํŠธ: [10, 20, 30]
reverse ํ›„์˜ ๋ฆฌ์ŠคํŠธ: [30, 20, 10]
insert(2, 222) ํ›„์˜ ๋ฆฌ์ŠคํŠธ: [30, 20, 222, 10]
20๊ฐ’์˜ ์œ„์น˜: 1
remove(222) ํ›„์˜ ๋ฆฌ์ŠคํŠธ: [30, 20, 10]
extend([77,88,77]) ํ›„์˜ ๋ฆฌ์ŠคํŠธ: [30, 20, 10, 77, 88, 77]
77๊ฐ’์˜ ๊ฐœ์ˆ˜: 2

์˜ˆ์ œ 6) ๋‹ค์ฐจ์› ๋ฆฌ์ŠคํŠธ๊ฐ€ ์ง€์›๋œ๋‹ค.
2์ฐจ์› ๋ฆฌ์ŠคํŠธ๋ฅผ ์„ ์–ธํ•˜๊ณ  2์ฐจ์› ๋ฆฌ์ŠคํŠธ ์š”์†Œ ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค. 

aa = [[1,2,3,4],
    [5,6,7,8],
    [9,10,11,12]]
print(aa[0][0])
print(aa[0])
print(aa[1][2])

๊ฒฐ๊ณผ)

1
[1, 2, 3, 4]
7

2.4 ํŠœํ”Œ p. 91

๋ณ€์ˆ˜์— ๊ฐ’์„ ์ €์žฅํ•  ๋•Œ ( )(๊ด„ํ˜ธ)๋กœ ๋ฌถ์–ด์ฃผ๋ฉด ํŠœํ”Œ์ด ๋˜๋ฉฐ ๊ฐ ๊ฐ’์€ ,(์ฝค๋งˆ)๋กœ ๊ตฌ๋ถ„ํ•ด์ค๋‹ˆ๋‹ค. ๋˜๋Š”, ๊ด„ํ˜ธ๋กœ ๋ฌถ์ง€ ์•Š๊ณ  ๊ฐ’๋งŒ ์ฝค๋งˆ๋กœ ๊ตฌ๋ถ„ํ•ด๋„ ํŠœํ”Œ์ด ๋ฉ๋‹ˆ๋‹ค.
์ฐธ๊ณ : https://dojang.io/mod/page/view.php?id=2201

๋ฆฌ์ŠคํŠธ์™€ ๊ฑฐ์˜ ์œ ์‚ฌํ•œ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ์ง€๋งŒ ๋ฆฌ์ŠคํŠธ๋Š” ์š”์†Œ ๊ฐ’์„ ๋ณ€๊ฒฝ ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ
ํŠœํ”Œ์€ ํ•œ ๋ฒˆ ๊ฐ’์„ ์ •ํ•˜๋ฉด ๋‚ด๋ถ€์˜ ๊ฐ’์„ ๋ฐ”๊ฟ€ ์ˆ˜๊ฐ€ ์—†๋‹ค. ์ฝ๊ธฐ ์ „์šฉ์ด๋‹ค.

(,) ์†Œ๊ด„ํ˜ธ๋กœ ์—ด๊ณ  ๋‹ซ๋Š”๋‹ค. ๊ด„ํ˜ธ๋Š” ์ƒ๋žต ๊ฐ€๋Šฅํ•˜๋‹ค. 

 ('red', 4, 'python', True)
 (1, 2, 3)
 tu = (10, "์žฅ๋™๊ฑด", 23, "์„œ์šธ")
tu 10 ์žฅ๋™๊ฑด 23 ์„œ์šธ
  tu[0] tu[1] tu[2] tu[3]

์˜ˆ์ œ 1) ๋ฌธ์ž์—ด๊ณผ ํŠœํ”Œ ํƒ€์ž… ๊ด€๊ณ„๋ฅผ ๋ณด์—ฌ์ค€๋‹ค. 

str = "ํŒŒ์ด์ฌ ๋ฌธ์ž์—ด"
print(str[0])
print(str[-1])
#str[-1] = '๋ ฌ' #ํŠœํ”Œ์€ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†๋‹ค.

card = 'red', 4, 'python', True
print(card)
print(card[1])
#card[0] = 'blue' #ํŠœํ”Œ์€ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†๋‹ค.

๊ฒฐ๊ณผ)

ํŒŒ
์—ด
('red', 4, 'python', True)
4

์˜ˆ์ œ 2) ๋ฌธ์ž์—ด๊ณผ ํŠœํ”Œ์˜ ๊ด€๊ณ„๋ฅผ ์„ค๋ช…ํ•œ๋‹ค. 
์ „์ฒด ๋ฌธ์ž์—ด์„ ๋ฐ”๊ฟ€ ์ˆ˜๋Š” ์žˆ์ง€๋งŒ, ํ•˜๋‚˜๋งŒ์€ ๋ฐ”๊ฟ€ ์ˆ˜ ์—†๋‹ค.

one = 'ํ•˜๋‚˜' #๋ฌธ์ž์—ด ์„ ์–ธ
print(type(one))
one = "์›" #๋ฌธ์ž์—ด ๊ฐ’ ์ „์ฒด๋ฅผ ๋ณ€๊ฒฝ
print(one)
two = '๋‘˜'
print(type(two))
#two[0] = 'ํˆฌ' #two ๋ณ€์ˆ˜์˜ ์ฒซ ๋ฒˆ์จฐ ์š”์†Œ ๊ฐ’ ๋ณ€๊ฒฝ(์˜ค๋ฅ˜)
print(two[0])

๊ฒฐ๊ณผ)

<class 'str'>
์›
<class 'str'>
๋‘˜

์˜ˆ์ œ 3) ํŠœํ”Œ ๋ณ€์ˆ˜๋กœ ์„ ์–ธ๋œ ๊ฐ๊ฐ์˜ ์š”์†Œ ๊ฐ’๋“ค์„ ํ•˜๋‚˜์˜ ๋ณ€์ˆ˜๋กœ ๋ฆฌํ„ด ๋ฐ›๋Š”๋‹ค.
ํŒŒ์ด์ฌ์€ ๋Œ€๋ฌธ์ž๋กœ True, False์ด๋‹ค. 

card = 'red', 4, 'python', True #card ํŠœํ”Œ์„ ๋‹ค์–‘ํ•œ ํƒ€์ž…์˜ ์š”์†Œ๋กœ ์„ ์–ธ
a, b, c, d = card #card์˜ 4๊ฐœ์˜ ์š”์†Œ ๊ฐ’๋“ค์„ a-d ๋ณ€์ˆ˜์— ํ• ๋‹น
print(a)
print(b)
print(c)
d = False #d ๋ณ€์ˆ˜์˜ ๊ฐ’์„ ์ˆ˜์ •
print(d)

๊ฒฐ๊ณผ) ํŠœํ”Œ ์ผ ๋•Œ๋Š” ๊ฐ’์„ ๋ชป ๋ฐ”๊พธ๋Š” ๋ฐ ์ผ๋ฐ˜ ๋ณ€์ˆ˜๊ฐ€ ๋˜๋ฏ€๋กœ ๊ฐ’์„ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋‹ค.

red
4
python
False

๋ฌธ์ œ ํ’€์–ด๋ณด๊ธฐ) 
Q1) ์˜ํ™” ์ œ๋ชฉ์„ movie_rank ์ด๋ฆ„์˜ ๋ฆฌ์ŠคํŠธ์— ์ €์žฅํ•ด๋ณด์„ธ์š”. (์ˆœ์œ„ ์ •๋ณด๋Š” ์ €์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค.)
์ˆœ์œ„ ์˜ํ™”
1 ๋‹ฅํ„ฐ ์ŠคํŠธ๋ ˆ์ธ์ง€
2 ์Šคํ”Œ๋ฆฟ
3 ๋Ÿญํ‚ค

Q2) moive_rank ๋ฆฌ์ŠคํŠธ ๋งจ ๋งˆ์ง€๋ง‰์— "๋ฐฐํŠธ๋งจ"์„ ์ถ”๊ฐ€ํ•˜๋ผ.

Q3) movie_rank ๋ฆฌ์ŠคํŠธ์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ๋„ค ๊ฐœ์˜ ์˜ํ™” ์ œ๋ชฉ์ด ๋ฐ”์ธ๋”ฉ๋˜์–ด ์žˆ๋‹ค. 
"์Šˆํผ๋งจ"์„ "๋‹ฅํ„ฐ ์ŠคํŠธ๋ ˆ์ธ์ง€"์™€ "์Šคํ”Œ๋ฆฟ" ์‚ฌ์ด์— ์ถ”๊ฐ€ํ•˜๋ผ.
movie_rank = ['๋‹ฅํ„ฐ ์ŠคํŠธ๋ ˆ์ธ์ง€', '์Šคํ”Œ๋ฆฟ', '๋Ÿญํ‚ค', '๋ฐฐํŠธ๋งจ']

Q4) movie_rank ๋ฆฌ์ŠคํŠธ์—์„œ '๋Ÿญํ‚ค'๋ฅผ ์‚ญ์ œํ•˜๋ผ.
movie_rank = ['๋‹ฅํ„ฐ ์ŠคํŠธ๋ ˆ์ธ์ง€', '์Šˆํผ๋งจ', '์Šคํ”Œ๋ฆฟ', '๋Ÿญํ‚ค', '๋ฐฐํŠธ๋งจ']

Q5)
movie_rank ๋ฆฌ์ŠคํŠธ์—์„œ '์Šคํ”Œ๋ฆฟ'๊ณผ '๋ฐฐํŠธ๋งจ'์„ ์‚ญ์ œํ•˜๋ผ. 

movie_rank = ['๋‹ฅํ„ฐ ์ŠคํŠธ๋ ˆ์ธ์ง€', '์Šˆํผ๋งจ', '์Šคํ”Œ๋ฆฟ', '๋ฐฐํŠธ๋งจ']

์ฝ”๋“œ)

movie_rank = ['๋‹ฅํ„ฐ ์ŠคํŠธ๋ ˆ์ธ์ง€', '์Šคํ”Œ๋ฆฟ', '๋Ÿญํ‚ค']
print(movie_rank)
movie_rank.append('๋ฐฐํŠธ๋งจ')
print(movie_rank)
movie_rank.insert(1,'์Šˆํผ๋งจ')
print(movie_rank)
movie_rank.remove('๋Ÿญํ‚ค')
print(movie_rank)
movie_rank.remove('์Šคํ”Œ๋ฆฟ')
movie_rank.remove('๋ฐฐํŠธ๋งจ')
print(movie_rank)

๊ฒฐ๊ณผ)

['๋‹ฅํ„ฐ ์ŠคํŠธ๋ ˆ์ธ์ง€', '์Šคํ”Œ๋ฆฟ', '๋Ÿญํ‚ค']
['๋‹ฅํ„ฐ ์ŠคํŠธ๋ ˆ์ธ์ง€', '์Šคํ”Œ๋ฆฟ', '๋Ÿญํ‚ค', '๋ฐฐํŠธ๋งจ']
['๋‹ฅํ„ฐ ์ŠคํŠธ๋ ˆ์ธ์ง€', '์Šˆํผ๋งจ', '์Šคํ”Œ๋ฆฟ', '๋Ÿญํ‚ค', '๋ฐฐํŠธ๋งจ']
['๋‹ฅํ„ฐ ์ŠคํŠธ๋ ˆ์ธ์ง€', '์Šˆํผ๋งจ', '์Šคํ”Œ๋ฆฟ', '๋ฐฐํŠธ๋งจ']
['๋‹ฅํ„ฐ ์ŠคํŠธ๋ ˆ์ธ์ง€', '์Šˆํผ๋งจ']


Q6)
๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•ด๋ณด๊ณ  ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ์›์ธ์„ ์„ค๋ช…ํ•˜๋ผ.

t = (1, 2, 3)
t[0] = 'a'

TypeError: 'tuple' object does not support item assignment

ํŠœํ”Œ์€ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†๋‹ค.


2.5 ๋”•์…”๋„ˆ๋ฆฌ

key๊ฐ’๊ณผ value๊ฐ’์ด ํ•œ ์Œ์œผ๋กœ ์ €์žฅ๋˜๋Š” ํƒ€์ž…์ด๋‹ค.
value ๊ฐ’์€ ํŠœํ”Œ๊ณผ ๋‹ค๋ฅด๊ฒŒ ๋ณ€๊ฒฝ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

{,} ์ค‘๊ด„ํ˜ธ๋กœ ์—ด๊ณ  ๋‹ซ๋Š”๋‹ค.

{dict = ["๋ฒˆํ˜ธ":10, "์„ฑ๋ช…": "์žฅ๋™๊ฑด", "๋‚˜์ด":23, "์‚ฌ๋Š”๊ณณ":"์„œ์šธ"}
dict["์‚ฌ๋Š”๊ณณ"] = "๊ฒฝ๊ธฐ๋„"
dic (value) 10 ์žฅ๋™๊ฑด 23 ์„œ์šธ
(key) dic[๋ฒˆํ˜ธ] dic[์„ฑ๋ช…] dic[๋‚˜์ด] dic[์‚ฌ๋Š”๊ณณ]

 

์˜ˆ์ œ 1)

dict = {'๋ฒˆํ˜ธ':10, '์„ฑ๋ช…': '์žฅ๋™๊ฑด', '๋‚˜์ด':23, '์‚ฌ๋Š”๊ณณ':'์„œ์šธ'}

print(dict)
print(type(dict))
print(dict['๋‚˜์ด'])
dict['๋‚˜์ด'] = 24
print(dict['๋‚˜์ด'])
dict['์ง์—…'] = '๋ฐฐ์šฐ'
print(dict)
print(dict.keys())
print(dict.values())
print('์‚ฌ๋Š”๊ณณ' in dict) #ํ‚ค ๊ฐ’ ์กด์žฌ ์—ฌ๋ถ€: True
del dict['์‚ฌ๋Š”๊ณณ']
print('์‚ฌ๋Š”๊ณณ' in dict) #ํ‚ค ๊ฐ’ ์กด์žฌ ์—ฌ๋ถ€: False
print(dict)

๊ฒฐ๊ณผ)

{'๋ฒˆํ˜ธ': 10, '์„ฑ๋ช…': '์žฅ๋™๊ฑด', '๋‚˜์ด': 23, '์‚ฌ๋Š”๊ณณ': '์„œ์šธ'}
<class 'dict'>
23
24
{'๋ฒˆํ˜ธ': 10, '์„ฑ๋ช…': '์žฅ๋™๊ฑด', '๋‚˜์ด': 24, '์‚ฌ๋Š” ๊ณณ': '์„œ์šธ', '์ง์—…': '๋ฐฐ์šฐ'}
dict_keys(['๋ฒˆํ˜ธ', '์„ฑ๋ช…', '๋‚˜์ด', '์‚ฌ๋Š” ๊ณณ', '์ง์—…'])
dict_values([10, '์žฅ๋™๊ฑด', 24, '์„œ์šธ', '๋ฐฐ์šฐ'])
True
False
{'๋ฒˆํ˜ธ': 10, '์„ฑ๋ช…': '์žฅ๋™๊ฑด', '๋‚˜์ด': 24, '์ง์—…': '๋ฐฐ์šฐ'}

728x90
๋ฐ˜์‘ํ˜•

'๐ŸŒณBootcamp Revision 2023โœจ > Python, Flask, SQL' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[48] 230308 Ch. 6 Flask๋ฅผ ํ™œ์šฉํ•œ ์„ผ์„œ ์ œ์–ด: 5. Flask ์›นํŽ˜์ด์ง€, 6. IP, Port, Process ๊ฐœ๋… ์žก๊ธฐ, 7. cron๊ณผ daemon ๊ฐœ๋… ์žก๊ธฐ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 48์ผ]  (1) 2023.03.08
[47] 230307 Ch. 6 Flask๋ฅผ ํ™œ์šฉํ•œ ์„ผ์„œ ์ œ์–ด: 1. Flask ์„ธํŒ…ํ•˜๊ธฐ, 2. Flask ์›น์„œ๋ฒ„ ๊ตฌ์ถ•ํ•˜๊ธฐ, 3. Flask ๋ผ์šฐํŒ…, 4. Flask LED ์ œ์–ดํ•˜๊ธฐ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 47์ผ]  (0) 2023.03.07
[42] 230227 Ch. 3 ๋ผ์ฆˆ๋ฒ ๋ฆฌ ํŒŒ์ด๋ฅผ ์œ„ํ•œ ํŒŒ์ด์ฌ ๊ธฐ์ดˆ ๋ฐฐ์šฐ๊ธฐ: 5. ํŒŒ์ด์ฌ ํด๋ž˜์Šค์™€ ๋ชจ๋“ˆ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 42์ผ]  (0) 2023.02.27
[41] 230224 Ch. 3 ๋ผ์ฆˆ๋ฒ ๋ฆฌ ํŒŒ์ด๋ฅผ ์œ„ํ•œ ํŒŒ์ด์ฌ ๊ธฐ์ดˆ ๋ฐฐ์šฐ๊ธฐ: 3. ํŒŒ์ด์ฌ ์ œ์–ด๋ฌธ, 4. ํŒŒ์ด์ฌ ํ•จ์ˆ˜ ์‚ฌ์šฉ๋ฒ• [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 41์ผ]  (0) 2023.02.24
Comments