여러가지/Python

Day 4 - 모듈, Random, 리스트, 내장함수 .split(), index()

15June 2023. 12. 7. 02:03

● 학습 내용

 

1) 모듈

 

 

[참고] 사이트

https://www.askpython.com/

 

AskPython - Python Tutorials for Beginners and Experienced Programmers

Python Tutorials for Beginners and Experienced Programmers

www.askpython.com

 

2) Random

3) 리스트

names = ["Korea", "Japan", "US", "Canada"]

 

ex) 누가 점심을 살까요?

import random

names = names_string.split(", ")
num = random.randint(0,len(names)-1)

print(f"{names[num]} is going to buy the meal today!")

# names = names_string.split(", ")

=> 여러 명의 이름을 ,를 사용하여 입력

# len(names): list의 항목 수 셀 때도 사용

 

[참고] 튜토리얼

https://docs.python.org/3.8/tutorial/introduction.html

 

3. An Informal Introduction to Python — Python 3.8.17 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

 

 

ex) 보물 찾기

https://github.com/yooyijun15/Python/tree/main/Day4

# index(): 인덱스 찾는 내장 함수, 리스트 값의 인덱스도 찾음

 

 

(가위바위보)

● GIT URL : https://github.com/yooyijun15/Python/tree/main/Day4