코딩 테스트를 준비하기 위해서 언어를 정하기까지 많은 고민을 했습니다!
그래서 결론적으로 정한건 파이썬!
원래도 파이썬 문법을 알고 쓸 줄은 알지만, 책을 따로 구입해서 깊게 판 적은 없습니다!
코테 언어를 파이썬으로 정했으니 이 책으로 파이썬 기초를 빠르게 다진 후 준비하려고 합니다!
1. 리터럴 (Literal): 값 그 자체를 의미, 변하지 않는 데이터
10 # 숫자 리터럴
"Hello" # 문자열 리터럴
10과 "Hello"는 리터럴 값
2. 키워드 (Keyword): 파이썬에서 의미를 가진 예약어로, 변수명으로 사용할 수 없다. (if, while..)
if True:
print("This is a keyword!")
if는 조건문을 나타내는 파이썬 키워드
3. 식별자 (Identifier): 변수나 함수의 이름
my_variable = 10
my_variable은 식별자
4. 자료형 (Data Type): 데이터의 종류
number = 5 # 숫자형
text = "Hello" # 문자열형
5. 문자열 (String) 및 문자열 연산자
greeting = "Hello, Python!"
greeting = "Hello, " + "Python!"
repeat = "Python! " * 3
print(greeting) # Hello, Python!
print(repeat) # Python! Python! Python!
6. 숫자 (Numbers): 정수(int), 실수(float)
integer_num = 10 # 정수
float_num = 3.14 # 실수
7. 변수와 복합대입연산자
x = 5
x += 3 # x = x + 3과 동일
print(x) # 결과는 8
8. input() 함수와 자료형 변환: 사용자로부터 입력을 받음
user_input = input("숫자를 입력하세요: ") # 문자열로 입력 받음
number = int(user_input) # 입력 값을 정수로 변환
print(number + 10)
input()으로 받은 값은 기본적으로 문자열이므로, int()를 사용해 정수로 변환한 후 계산.
9. format 함수와 split 함수, f-문자열
- format() 함수
name = "John"
age = 25
print("My name is {} and I am {} years old.".format(name, age))
- split() 함수
sentence = "Python is fun"
words = sentence.split()
print(words) # ['Python', 'is', 'fun']
- f-문자열
name = "Alice"
age = 30
print(f"My name is {name} and I am {age} years old.")
10. 불 자료형 (Boolean)
a = True
b = False
print(5 > 3) # True
print(3 == 4) # False
11. if 조건문
age = 20
if age >= 18:
print("You are an adult.")
- elif, else
score = 85
if score >= 90:
print("A grade")
elif score >= 80:
print("B grade")
else:
print("C grade")
12. 리스트
numbers = [1, 2, 3, 4, 5]
print(numbers[0]) # 1
fruits = ["apple", "banana"]
fruits.append("cherry") # 리스트에 요소 추가
print(fruits) # ['apple', 'banana', 'cherry']
fruits.remove("banana") # 리스트에서 요소 제거
print(fruits) # ['apple', 'cherry']
13. for 반복문과 리스트
for i in range(5):
print(i)
_____________________________________________________________________________________________
numbers = [1, 2, 3, 4]
total_sum = 0
for num in numbers:
total_sum += num
print(total_sum) # 10
_____________________________________________________________________________________________
total_product = 1
for num in numbers:
total_product *= num
print(total_product) # 24
_____________________________________________________________________________________________
for i in range(3):
for j in range(2):
print(f"i={i}, j={j}")
_____________________________________________________________________________________________
numbers = [1, 2, 3]
print(*numbers) # 1 2 3
14. 딕셔너리의 요소 변경, 추가, 제거
person = {"name": "John", "age": 25}
for key, value in person.items():
print(key, ":", value)
___________________________________________
person = {"name": "John", "age": 25}
person["age"] = 26 # 변경
person["city"] = "New York" # 추가
del person["name"] # 제거
15. 리스트, 딕셔너리와 관련된 기본 함수
- 리스트 함수: len(), append(), sort()
- 딕셔너리 함수: keys(), values(), items()
numbers = [1, 2, 3, 4]
print(len(numbers)) # 리스트 길이
print(sum(numbers)) # 리스트 총합
person = {"name": "Alice", "age": 30}
print(person.keys()) # 딕셔너리의 키들
16. join() 함수
words = ["Hello", "Python"]
sentence = " ".join(words)
print(sentence) # "Hello Python"
17. 함수 매개변수, 가변 매개변수 함수 기본 매개변수
def add(a, b):
return a + b
print(add(3, 5)) # 8
__________________________________
def add_all(*args):
return sum(args)
print(add_all(1, 2, 3, 4)) # 10
__________________________________
def greet(name="Guest"):
print(f"Hello, {name}!")
greet() # Hello, Guest!
greet("Alice") # Hello, Alice!
18. 튜플, 이뮤터블 자료, 뮤터블 자료
- 튜플: 변경할 수 없는(immutable) 자료형으로, 리스트와 유사하지만 수정 불가능.
- 뮤터블 자료: 수정 가능한 자료형(예: 리스트).
- 이뮤터블 자료: 수정 불가능한 자료형(예: 튜플, 문자열).
numbers = (1, 2, 3) # 튜플
numbers[0] = 10 # 에러 발생 (튜플은 수정 불가)
19. 콜백함수, map()/filter() 함수
- 콜백 함수: 다른 함수에 인자로 전달되어 실행되는 함수.
- map() 함수: 리스트의 각 요소에 함수를 적용.
- filter() 함수: 리스트의 요소 중 조건을 만족하는 것만 반환.
numbers = [1, 2, 3, 4]
squares = list(map(lambda x: x**2, numbers))
print(squares) # [1, 4, 9, 16]
even_numbers = list(filter(lambda x: x % 2 == 0, numbers))
print(even_numbers) # [2, 4]
20. 람다, key 키워드 매개변수
words = ["apple", "banana", "cherry"]
words_sorted = sorted(words, key=lambda x: len(x))
print(words_sorted) # ['apple', 'cherry', 'banana']
총평) 예제가 연습하기에 좋고, 강의도 상세하게 잘 설명해주십니다!
'etc > 독서' 카테고리의 다른 글
| [독서] 이것이 취업을 위한 코딩테스트다. (그리디) (0) | 2024.12.30 |
|---|---|
| [독서] 이것이 취업을 위한 코딩 테스트다. (3) | 2024.12.30 |
| [독서] 이것이 취업을 위한 코딩 테스트다 with 파이썬 (1) | 2024.09.22 |