본문 바로가기

파이썬 기초

[파이썬 기초] 연산자 문법, 튜플

증감연산자
a+=10
a*=10

관계연산자
a==b :a랑 b가 같은지 판별
a!=b : a가 b와 다른지 판별

==>true,false로 반환

a>b
a<b

a=“abc”
b=“def”
print(a<b)

사전순이기에 true임

논리연산자
A and B :모두 참인지 판별
A or B : A혹은 B가 참인지 판별
not A: A가 거짓인지 판별

a =True
b=False

print(a and b)
print(a or b)
print(not a)



튜플: 리스트와 비슷한 자료형(변경불가)

tuple=(1,2,3)
for i in tuple:
print(i)

list1=[1,2,3]
list2=[4,5,6]
tuple=(list1,list2)
print(tuple[0][1])

tuple[0]=[5,6,7] —> 오류
tuple[0][1]=6      —> 가능(리스트니까)


tuple=(1,2,3,4,5,6,7,8)
print(tuple[0:5]*3)


—>tuple[0:5]가 3번 반복되서 출력됌





반응형