반응형
-
[파이썬]불 자료형 - bool 함수로 참과 거짓 판별하기 이번 글에서는 자료형이 참(True)과 거짓(False)인지 나타내는 불(bool) 자료형을 다룬다. 자료형의 참과 거짓이라는 것의 의미와 bool 자료형의 활용에 대해 알아보자. 불(bool) 자료형 이해하기 불(bool) 자료형이란? >>> a = True >>> a True >>> type(a) >>> b = false # false를 변수명으로 인식하여 에러 발생 Traceback (most recent call last): File "", line 1, in NameError: name 'false' is not defined bool 자료형은 자료형의 참과 거짓을 판별한다. bool 자료형은 자료형이 참인 경우에 True, 거짓인 경우에 False를 반환하는데, True, False 두 가지의..
-
[파이썬]while, for 반복문 탈출과 계속하기 - break, continue 이번 포스팅에서는 while과 for 같은 반복문에서 조건문이 True인 경우에도 반복문을 탈출할 수 있게 해주는 break와 반복문의 시작 지점으로 돌아가게 해주는 continue에 대해 알아본다. 반복문 강제로 탈출하기 - break break로 반복문 강제로 탈출하기 while문의 조건문이 True일 경우에도 break로 while문을 빠져나올 수 있다. count = 0 while True: count += 1 print('현재 카운트 %d' %count) if count == 5: break print('while문 탈출') #결과 출력 현재 카운트 1 현재 카운트 2 현재 카운트 3 현재 카운트 4 현재 카운트 5 while문 탈출 위 예문을 보면 조건문은 항상 True이기 때문에 while문..
-
[파이썬]리스트 자료형의 인덱싱과 슬라이싱 문자열과 마찬가지로 리스트에서도 인덱싱과 슬라이싱을 할 수 있다. 예문을 통해서 확인해보자. 리스트의 인덱싱(Indexing) 리스트 인덱싱 방법 >>> a = [1, 2, 3] >>> a [1, 2, 3] >>> a[0] # 0번 위치의 요소값 반환 1 >>> a[2] # 2번 위치의 요소값 반환 3 리스트의 인덱싱은 문자열의 인덱싱과 매우 비슷하다. 리스트 역시 순서를 1이 아닌 0부터 세기 때문에 첫 번째 요소 값을 출력하기 위해서는 인덱싱 숫자를 0으로 해야 한다. 요소 값 수정 및 삭제 >>> a = [1, 2, 3] >>> a [1, 2, 3] >>> a[0] = 4 # 0번에 위치한 요소값 변경 >>> a [4, 2, 3] >>> del a[1] # a[1] 요소 리스트에서 삭제 >>> a ..
-
[파이썬]숫자 자료형 정리 - int, float, 사칙연산 숫자 자료형이란 숫자 형태로 이루어진 자료형이다. 이번 글에서는 흔히 사용되는 정수와 소수점이 있는 실수 자료형과 숫자형의 사칙연산에 대해 알아볼 것이다. 드물게 2진수, 8진수, 16진수도 있지만 이 글에서는 다루지 않겠다. 숫자형 종류와 주의사항 1. 정수형(Integer) 정수형은 정수로 되어있는 자료형을 말한다. 양의 정수, 음의 정수, 0 모두 같은 Integer 타입에 속하며 'int'로 표시된다. 변수 선언은 변수명 = 값, 혹은 변수명 = int(값) 이렇게 하면 된다. >>> a = 100 >>> b = int(-90) >>> c = 0 >>> type(a), type(b), type(C) (, , ) 파이썬의 내장 함수 type을 이용하여 각 변수들의 자료형을 보면 모두 'int'로 나..
-
25.09.24 - Festival English 1. What is your favorite festival, and why do you enjoy it? - I love watching game competitions, particularly Legue of Legend which is an MOBA game. Around the end of year, The World Chapionship is held where many different teams from other countries participate in and play at each other. As I grow older and older, the more I enjoy at home than outside. I like watching the game matches from TV w.. -
25.09.23 - Placing an order at a cafe 1. What type of coffee do you usually order at a cafe, and why? - I usally order an iced americano when I go to a cafe. I actually used to have frappuchino everytime I was at a cafe, but since I made up my mind to cut back on sugar, I haven't had frappuchino things very much. Actually I'm trying to cut back on caffeine too, but I have no other options but americano. The main reason I go to cafes.. -
25.09.23 - Grocery shopping 1. What do you usually buy when you go grocery shopping? - I always grab some zero-sugar drinks like Pepsi Zero Lime. It's my absolute favorite. I also like to check out the deli section, especially right before the store closes, because that's when they have a lot of food on sale. The food always smells amazing and is cheaper, so I usually end up buying some, even though it's often not as tasty.. -
25.09.16 - My exercise routine 1. What kind of exercise do you like the most? Why? - I like weight training the most because I can see the results of my hard work. While cardio is great for heart health and I know I need it, I think men should have some muscle. Plus cardio like running takes a lot of time and can be boring. Keeping my workout sessions short helps me stay consistent.2. How often do you work out? - I used to hi.. -
25.09.16 - Sticking to my routine 1. What is your morning routine? - When I wake up, the very first thing I do is drink some water because I always wake up feeling a bit dehydrated. So, I walk to the kitchen, turn on the purfier and have a glass. - After drinking water, I get ready for work. I brush my teeth, wash my face and hair. And I put on some lotion. - Next, I make my bed unless my wife is still sleeping. I grab a corner..
반응형