a = 1
print(type(a))
나눗셈
a = 2
b = 5
print(a / b) //결과
print(a // b) //몫만
print(a % b) //나머지만
결과값 :
0.4
0
2
\n = 띄어쓰기
\t = 간격
\ [\,',"] = 문자 그대로 표현
a = "i love\n you"
print(a)
결과값 :
i love
you
이스케이프 안쓰고 싶으면 """ """ 쌍따옴표 3개하면 그대로 출력됨
a = "python"
print (a * 100)
결과값 : a를 100번 출력해라 (python 100번 나옴)
a = "Life is too short, You need Python"
print(a[0:4])
print(a[:4])
결과값 : Life
print(a[4:])
결과값 : is too short, You need Python
a[ 1 : 2 : 1 ]
이상 :미만 :간격(간격이 -이면 거꾸로 읽기임)
포멧스트링
%d = 정수
%s = 문자열 <<이걸로 엥간하면 다됨
%f = 실수형 >> %0.4f = 소수점 4개까지만 표시
예시
a = "I eat %d apples" %3
print(a)
결과값 : I eat 3 apples
number = 10
day = "three"
a = "I eat %d apples for %d days" % (number, day)
print(a)
결과값 I eat 10 apples for three days
a = "awesdf {age} jslkadjfl {name} sdaf".format(age=3,name="서창용")
or
age=3
name="서창용"
a = f"awesdf {age} jslkadjfl {name} sdaf"
print(a)
결과값 awesdf 3 jslkadjfl 서창용 sdaf
ex)find
count
소문자->대문자 : upper
대문자->소문자 : lower
양쪽공백지우기 : strip
replace
띄어쓰기기준으로 자름 : split()
: 기준으로 자름 split(:)
변수.함수()
a = "hobby"
print(a.find("o"))
결과값 = 1
없으면 = -1 나옴a = "hi"
print(a.upper())
결과값 : HI
a = "Life is too short, You need Python"
print(a.replace("Life","Your leg"))
결과값 : Your leg is too short, You need Python
a = "Your leg is too short, You need Python"
print(a.split())
결과값 :
['Your', 'leg', 'is', 'too', 'short,', 'You', 'need', 'Python']
삭제 del a[0]
리스트추가 append()
정렬 sort()
거꾸러 reverse()
특정인덱스추가 insert( n번째 인덱스에, n을 추가)
값제거 remove(지울값)
리스트요고 끄집어내기 pop()
숫자세기 count(해당숫자)
리스트확장(리스트를추가) extend(값,값,값~~)
a = [ 1, 2, 3, [3, 4,]]
print(a[3])
결과값 : 4
a = [ 1, 2, 3, [3, 4,]]
print(a[3][1])
결과값 : 4
a=[1,2,3]
a.pop()
3
>>a
[1,2]