현재 주피터 노트북이 있는 경로를 출력할 수 있다.
%pwd
Zen of Python
- 파이썬의 철학이 잘 담겨있는 Zen of Python 을 출력할 수 있다.
- import를 통해 파이썬의 라이브러리나 패키지를 가져올 수 있다.
import this
boolean
파이썬에는 명시적인 것이 암시적인 것보다 낫다라는 철학이 있다.
True 나 False는 0과 1로도 표현할 수 있으나 명시적으로 표현하기 위해 True와 False를 사용한다.
# True는 1과 같음을 표현하기
# 파이썬에서는 같음을 비교할 때 == 연산을 사용한다.
print(True== 1)
print(True=="1")
True != "1" # 문자열 1과 True는 다르다.
False != "1" # False 도 마찬가지이다.
False != "0" # 문자열 0과 False는 다르다.
True and False # and 는 조건 중 하나라도 False 라면 False가 된다.
True or False # or 는 하나만 True 라도 True가 된다.
True + False # True == 1, False == 0 과 같기 때문에 연산을 할 수 있다.
변수
숫자로 시작할 수 없으며, underbar(_)를 제외한 특수문자를 사용할 수 없다.
a=a+1 #변수할당
b=a+1
a==b #비교
문자열
참고자료: https://docs.python.org/3/tutorial/introduction.html#strings
3. An Informal Introduction to Python — Python 3.9.6 documentation
3. An Informal Introduction to Python In the following examples, input and output are distinguished by the presence or absence of prompts (>>> and …): to repeat the example, you must type everything after the prompt, when the prompt appears; lines that d
docs.python.org
til='today i learned'
til.lower() #소문자로 만들기
til.upper() #대문자로 만들기
address=" 서울특별시 강남구 역삼동 강남대로94길 15"
address.strip??
address.strip() #앞뒤 공백 제거
strip 메소드를 사용해 앞뒤 공백을 제거할 수 있다.
괄호안에서 shift tab 키를 누르면 도움말을 볼 수 있다.
또는 ??를 통해 소스코드 도움말을 확인할 수 있다.
문자열의 인덱싱과 슬라이싱
# 인덱싱으로 문자 가져오기
til[0] # 인덱싱ㅇ로 0번째 문자('t')를 출력한다.
til[:5] # [시작인덱스 :끝인덱스 + 1]로 'today'를 출력한다.
# 슬라이싱으로 문자가져오기
til[-1] # -1번째는 뒤에서 1번째 문자('d')를 출력한다.
리스트
참고자료: https://docs.python.org/3/tutorial/introduction.html#lists
3. An Informal Introduction to Python — Python 3.9.6 documentation
3. An Informal Introduction to Python In the following examples, input and output are distinguished by the presence or absence of prompts (>>> and …): to repeat the example, you must type everything after the prompt, when the prompt appears; lines that d
docs.python.org
[] # 비어있는 리스트를 만든다
['경찰차','소방차'] #비어있는 리스트에 원소를 추가
car=['경찰차','소방차','구급차','녹차'] #car 변수에 담기
리스트에 원소 추가 삭제하기
append, remove를 이용하여 원소를 추가 또는 삭제할 수 있다.
car.append('녹차') # 녹차 원소 추가하기
car.remove('녹차') # 녹차 원소 제거하기
'빅데이터 관련 자료 > Python' 카테고리의 다른 글
파이썬 기초 - 6 (0) | 2021.08.02 |
---|---|
파이썬 기초 - 5 (0) | 2021.07.29 |
파이썬 기초 - 4 (0) | 2021.07.26 |
파이썬 기초-3 (0) | 2021.07.22 |
파이썬 기초 - 2 (0) | 2021.07.21 |