목록Python (4)
나의 블로그
정수 변환 - int()실수 변환 - float()문자열 변환 - str()문자 변환 - chr()불리언 변환 - bool()>>> print(int(3.14))3>>> print(float(3))3.0>>> print(type(str(3)))>>> print(type(chr(3)))>>> print(bool(3))True>>> print(bool(-3))True>>> print(bool(0))False>>> a = 3>>> print(type(a))>>> print(a + 3)6>>> print(str(a) + "3")33
>>> hello1 = 'Hello, world!'>>> print(hello1)Hello, world!>>> hello2 = "Hello, world!">>> print(hello2)Hello, world!>>> print('Hello, "Python"')Hello, "Python">>> print("Hello, 'Python'")Hello, 'Python'
IndentationError: unexpected indent (들여쓰기 오류)import matplotlib.pyplot as pltx = [10, 20, 30, 10, 30, 20, 30, 50, 20, 10, 20] plt.hist(x) plt.show()수정import matplotlib.pyplot as pltx = [10, 20, 30, 10, 30, 20, 30, 50, 20, 10, 20]plt.hist(x)plt.show()참고https://korbillgates.tistory.com/92 [파이썬] 파이썬 에러 IndentationError: expected an indented block안녕하세요 한주현입니다. 오늘은 파이썬 스크립트 작성 시 자주 보게되는 오류 중 하나인, Inde..
import random 1. random.randint2. random.randrange3. random.random4. random.choice n = random.randint(start, end)start부터 end까지 중 하나를 난수로 생성n = random.randrange(start, end)start부터 end-1 중 하나를 난수로 생성n = random.random()0보다 크거나 같고 1보다 작은 수 중 하나를 난수로 생성n = random.choice(['red', 'blue', 'green'])list 원소 중 하나를 난수로 추출n = random.choice(range(start, end))range()에서 생성된 수(start ~ end-1) 중 하나를 추출n = random.c..