티스토리 뷰
정리라기보단 걍 내용을 다 적었다
a=1
b=4
c = "hello world"
d="""ho"ho"hooh"""
e='''ghehe'''
print(a//b) #나누기 할때 몫으로 나오려면 // 두개
print(a/b) #기본적으로 정수를 나눠도 float 형이 나온다
print(type(a/b))
print(type(c))
print(type(d))
print(d)
a="Life is too short, You need py"
print(a)
number=10
day="three"
a="I ate %d apples. so I was sick for %s days" % (number,day)
print(a)
print(a)
#3.6이상만
name = "int"
a= f"나의 이름은 {name}입니다"
print(a)
#포메팅
a="aasdf {age} asd fasd fasdf {name} asdfasdf" .format(name="안녕",age="23")
print(a)
#인덱싱
print(a[0]);
print(a[-1])
print(a[-2])
#슬라이싱
print(a[0:3]) # 0 1 2 까지 이상:미만:간격
print(a[0:7:2]) # 0 2 4 6
#문자열 포멧팅
c= "I eat %d apples. " % 3
b="I eat " + str(3) + " apples"
print(b)
print(c)
#정렬과 공백
a = "%3s" % "hi" # hi포함 10칸 hi가 맨뒤 오른쪽 정렬
print(a)
a = "%8.4f" % 3.42134234 #간격.소수점 남기는 자리 수
print(a)
#문자열 개수 세기
a="hobby"
print(a.count('b'))
#위치 알려주기
a="Python is best choice"
print(a.find('b')) #10번째 글자에 b있음
print(a.find('3')) #없으면 -1
#조인 문자열 삽입
a = ",".join("abcd") # abcd에 , 문자열 삽입
print(a)
a = ",".join(["a","b","c","d"])
print(a)
#upper lower
print("UPPER lower")
a= "hi HELLO"
print(a.upper())
print(a.lower())
print(a) #a값이 변하지 않아서 upper 하고 따로 변수에 저장해야함
#문자열 바꾸기 replace
a="Life is too short"
print(a.replace("Life","Your leg"))
#split 특정값 기준으로 나눈다 그냥 split()쓰면 뛰어쓰기 기준
a="abcd"
print(a.split())
a="a:be:c:d"
print(a.split(":"))
#하나의 변수에 여러 변수를 넣고 싶을때 리스트 활용
a=[1,2,"int","김정현",["김재원","Manse samdori"]] #리스트 안에 리스트 가능
print(a[4])
print(a[4][1])
#리스트 값 변경
a=["박주하","잠수","문재성"]
a[0:2]=["김정현","Stopmotion MaN"]
print(a)
a[0:1]=["김정현","Stopmotion MaN"] #기존에 0:1 범위에 있는 값을 오른쪽값으로 변경
print(a)
a[0:2]=[] # 빈리스트로 교체 즉 삭제
print(a)
#또는 del 함수 사용
print("del")
a=["박주하","잠수","문재성"]
del a[1] #이건 혼자 모양이 왜이러냐
print(a)
#append 추가
a=["박주하","잠수","문재성"]
a.append("시우버") #맨뒤에 추가
print(a)
#sort 정렬
a=[1,5,3]
a.sort() #문자는 가나다 숫자는 크기
print(a)
#리스트 뒤집기 reverse
a=[1,5,3,5]
a.reverse()
print(a)
#index(값) 찾고자하는 값이 몇번 인덱스에 있나 반환 첫번째만 반환
print(a.index(5)) #5번이 1번 인덱스에 있다
#print(a.index(4)) 없으면 에러
#remove 특정 값제거 (인덱스 아님)
a=[1,5,3,1,1,1]
a.remove(1)
print(a)
#pop
print("pop")
a=[1,5,4]
print(a.pop()) # 마지막 값 튀어나감(제거) 나가는 값이 반환값
print(a)
#count
print("count")
a=[1,5,3,1,1,1]
print(a.count(1))
print(a.extend([2,3])) #extent 확장하다는 뜻 끝에 2,3 넣어서 확장
#extent 반환값은 None이다
print(a)
0
0.25
<class 'float'>
<class 'str'>
<class 'str'>
ho"ho"hooh
Life is too short, You need py
I ate 10 apples. so I was sick for three days
I ate 10 apples. so I was sick for three days
나의 이름은 int입니다
aasdf 23 asd fasd fasdf 안녕 asdfasdf
a
f
d
aas
asf2
I eat 3 apples
I eat 3 apples.
hi
3.4213
2
10
-1
a,b,c,d
a,b,c,d
UPPER lower
HI HELLO
hi hello
hi HELLO
Your leg is too short
['abcd']
['a', 'be', 'c', 'd']
['김재원', 'Manse samdori']
Manse samdori
['김정현', 'Stopmotion MaN', '문재성']
['김정현', 'Stopmotion MaN', 'Stopmotion MaN', '문재성']
['Stopmotion MaN', '문재성']
del
['박주하', '문재성']
['박주하', '잠수', '문재성', '시우버']
[1, 3, 5]
[5, 3, 5, 1]
0
[5, 3, 1, 1, 1]
pop
4
[1, 5]
count
4
None
[1, 5, 3, 1, 1, 1, 2, 3]
'프로그래밍 > 파이썬' 카테고리의 다른 글
이것이 취업을 위한 코딩테스트다 문법부분 공부2 라이브러리 (0) | 2021.02.20 |
---|---|
이것이 취업을 위한 코딩테스트다 문법부분 공부2 입출력 (0) | 2021.02.20 |
이것이 취업을 위한 코딩테스트다 문법부분 공부1 (0) | 2021.02.15 |
조코딩 파이썬 기초강좌3 (0) | 2021.02.06 |
조코딩 파이썬기초강좌 자료형2 정리 (0) | 2021.02.06 |
- Total
- Today
- Yesterday
- SW정글
- 티스토리챌린지
- 조코딩
- 체크인미팅1차실패
- CSS
- 파이썬
- error: src refspec master does not match any.
- nofap
- >선택자
- 이것이 취업을 위한 코딩테스트다
- 42seoul
- 오블완
- 체크인미팅3차성공
- 뺄샘
- 전체체크
- border-box
- 자식선택자
- 전역후후유증
- 코틀린
- 컨트롤F5
- 타이탄 철물점
- 브랜드로우
- SW마에스트로
- SW교육프로그램
- 기본문법
- 타이탄 철물점과 브랜드로우 워드프레스 1기 후기
- 문법
- 그때그때열심히
- 42서울
- 파이썬문법
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |