목록전체 글 (319)
개발자 뺚
import random random 모듈(Module)의 전처리문이다. random.randrange(number1, number2) random.randrange(number1, number2, step = number3) # example for _ in range(5): print(random.randrange(0, 5, step = 2)) # terminal 2 4 4 0 2 random 모듈의 randrange() 함수는 number1부터 number2 - 1까지의 정수 중 하나를 랜덤으로 반환하는 함수이다. 매개변수 step은 number1부터 다음 정수까지의 간격으로 default 값은 1이지만 number3의 값을 바꿔 이를 변경할 수 있다.
import datetime datetime 모듈(Module) 전처리문이다. from datetime import datetime datetime 모듈에는 날짜 및 시간을 저장할 수 있는 인스턴스(Instnace)를 만들 수 있는 datetime 클래스(Class)가 있다. 만약 하나의 날짜 및 시간만을 사용하고 싶다면 위와 같이 전처리문을 대신 사용할 수 있다. 이 경우 모듈과 클래스 이름이 같아 헷갈릴 수 있지만 datetime 모듈로부터 datetime 클래스를 인스턴스화해서 가져오겠다는 의미이다. datetime.now() # example now = datetime.now() print(now) print(now.year, "년",\ now.month, "월",\ now.day, "일",\ n..
string.upper() string.lower() # example string = "Hello World!" print(string.lower()) print(string.upper()) # terminal hello world! HELLO WORLD! upeer() 메서드는 문자열에 포함된 영어 소문자를 모두 대문자로 바꾸는 메서드이다. lower() 메서드는 반대로 문자열에 포함된 영어 대문자를 모두 소문자로 바꾸는 메서드이다. string.lstrip() string.rstrip() # example string = " WoW " print(string.lstrip() + ".") print(string.rstrip() + ".") # terminal WoW . WoW. lstrip() 메서드..
print(String) # example print("Hello World") 가장 기본적인 print() 함수의 사용이다. 출력할 문자열 또는 출력할 내용을 담은 변수를 매개변수로 전달한다. print(string1, string2) print(string1 + string2) print(string * 2) # example print("Hello", "World!") print("Hello" + "World!") print("Hello World!" * 2) # terminal Hello World! HelloWorld! Hello World!Hello World! 하나의 print() 함수 내에서 여러 문자열을 출력하는 방법에는 두가지가 있다. 첫번째로는 쉼표(,)를 이용하여 두번째로는 덧셈 연..
Keypad keypad = Keypad( makeKeymap(key), cp_row, cp_col, row, col ); # cp : connect_position # example const byte ROWS = 4; const byte COLS = 4; char key[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte cp_row[ROWS] = {6, 7, 8, 9}; byte cp_col[COLS] = {5, 4, 3, 2}; Keypad keypad = Keypad( makeKeymap(key), cp_row, cp_col, ROWS, COLS ); Keypad의 전처리..
LiquidCrystal_I2C lcd(address, row, column); # example LiquidCrystal_I2C lcd(0x27, 16, 2); LCD의 전처리 함수이다. 해당 내용은 MCP23008 기반, 32 LCD 16 x 2 (I2C)를 기준으로 작성되었다. address : I2C 주소. 0x20, 0x27, 0x3F 중 하나이다. column : LCD의 행 개수. 위 LCD 기준 16이다. row : LCD의 열 개수. 위 LCD 기준 2이다. lcd.init(); LCD 초기화 함수이다. LCD 화면 출력 이전 setup 문에서 실행시켜 준다. lcd.backlight(); LCD의 백라이트를 켜는 함수이다. lcd.noBacklight(); LCD의 백라이트를 끄는 함수..