본문 바로가기

전체 글21

[Python] 문자열 포맷팅 문자열 포맷이란 문자열 내에서 어떤 특정 값을 변화시키는 방법을 의미한다. % 서식 이용 print("%stule1 %style2" % (value1, value2)) %가 value 1의 값을 style1 으로, value2의 값을 style2로 변화시킨다. %d 는 10, 100 같은 정수 %f 는 0.5, 1.0 같은 실수 %c 는 "한" 같은 한 글자 %s 는 "안녕: 같은 두 글자 이상인 문자열 age = 19 userName = '홍길동' mailing = True # 학생 정보 나이 => 19 이름 => 홍길동 메일링 => True print('학생 정보 ', '나이 => ', age, '이름 => ', userName, '메일링 => ', mailing ) print('학생 정보 나이 =>.. 2022. 3. 1.
[Python] escape code 이스케이프 코드 \n -> 새로운 줄로 이동! print('\n줄바꿈\n연습') \t ->다음 탭으로 이동! print('\t탭키\t연습') \b ->뒤로 한 칸 이동! \\ -> \출력! \' -> '출력 print("글자가\'강조\' 되는 효과1") \" -> "출력 print("글자가\"강조\"되는 효과2") # 영희야 3줄 공백 처리후 놀자 print("영희야") print() print() print() print("놀자") print("영희야\n\n\n놀자") print("\t\t철수야\t놀자") print("철수야! \\ 놀자") # 철수야! \ 놀자 print("\"철수야!\" 놀자") # "철수야!" 놀자 print('==== 퀴즈 ====') # 퀴즈 : # 아래와 같이 3줄로 글자를 출력하는 4가지 .. 2022. 3. 1.
[C 언어] strlen 함수 정의 strlen - calculate the length of a string. string 의 길이를 계산한다. 시놉시스 #include #include int strlen(string s) 리턴 value this function returns the number of characters in s, excluding the terminating NUL byte (i.e., '\0'). 예시 #include #include #include int main(void) { string s = get_string("Input: "); printf("Output: "); for (int i = 0, n = strlen(s); i < n; i++) { printf("%c", s[i]); } printf("\n.. 2022. 2. 28.
[C 언어] Syntactic Sugar 문법적 설탕 문법적 설탕? 설탕은 맛있고 접근성도 좋고 쉽다! 문법적 설탕도 동일한 문법적 기능도 더 직관적이고 읽기 쉽게 만드는 것이다. 다음 예시를 보자. #include #include int main(void) { int scores[3]; scores[0] = get_int("Score: "); scores[1] = get_int("Score: "); scores[2] = get_int("Score: "); printf("Average: %f\n", (scores[0] + scores[1] + scores[2]) / 3.0); 3개의 스코어의 평균을 내는 코딩이다. 문법적 문제는 없지만 똑같은 걸 3번 반복해야 한다는 번거로움이 있다. 하지만 문법적 설탕을 사용한다면? #include #include int.. 2022. 2. 28.