본문 바로가기
728x90
반응형

Programming/Python16

[Python] 파이썬 반복문 for / while for# 반복문 for# 순서가 있는 자료형# 리스트, 문자열, range객체, 튜플, 딕셔너리# for 변수 in 시퀀스 자료 :# 명령문# 리스트 반복문for a in [1, 2, 3, 4] : print(a)# range객체 반복문 -> 순서가 있는 랜덤 데이터for b in range(10) : print(b)# 문자열 반복문msg = "자신감을 가져!"for word in msg : print(word)# 튜플# tuple1 =  while# 반복문 while -> 반복할 횟수가 정해지지 않았을 때 사용# while 조건식 :# 반복할 명령# 증감식i = 0 # 초기식while i >") if x == "exit" : break 2025. 1. 10.
[Python] 파이썬 조건문 if elif else # 조건문# 조건에 따라 실행할 명령이 달라 지는 것origin_pass = "1234"input_pass = input("패스워드를 입력하세요 >>>")if input_pass == origin_pass : print("로그인 성공")elif input_pass == "" : print("아무것도 입력하지 않음")else : print("로그인 실패") 2025. 1. 10.
[Python] 파이썬 리스트 자료형 list # 리스트 대괄호 []animals = ["사자", "호랑이", "원숭이"]# animals[0] = "사자"# animals[1] = "호랑이"# 데이터 추가 appendanimals.append("기린")# 데이터 할당animals[0] = "라이온"# 데이터 삭제 deldel animals[1]print(animals)list1 = [1, 2, 3, 4]# 슬라이싱# list[시작 : (끝+1)]list1[1:3] # 2,3# 길이 lenlen(list) # 4# 정렬 sort -> 오름차순 정렬list1.sort() 2025. 1. 10.
[Python] 파이썬 자료형 / 변수 / 연산 / 자료형 변환 # 주석 Comments# 숫자 자료형# 1. 정수형 : 소수점이 없는 수print(1, 2, 5, -1, sep="")# 2. 실수형 : 소수점이 있는 수print(0.1, 3.5, -4.5)# 문자 자료형 "" or ''print("python", end="")print("11111")# boolean 자료형print(True)print(False) # 변수name = "헬로"level = 1master = 80print(name, level, master)level = 20master = master + 1print(name, level, master) # 대입연산name = "하울"# 산술연산# - 숫자연산x = 5y = 2print(x + y) print(x - y) print(x * y) pr.. 2025. 1. 2.
728x90
반응형