#!/usr/bin/env python # coding: utf-8 # # Chapter 03 Strings and Console Output # # In[1]: # 01 문자열(Strings) brian = "Always look on the bright side of life!" # In[2]: # 02 연습(Practice) caesar = "Graham" praline = "John" viking = "Teresa" print(caesar) print(praline) print(viking) # In[3]: # 03 이스케이프 문자(Escaping characters) 'Help! Help! I\'m being repressed!' # In[4]: #04 인덱스로 접근하기 """ The string "PYTHON" has six characters, numbered 0 to 5, as shown below: +---+---+---+---+---+---+ | P | Y | T | H | O | N | +---+---+---+---+---+---+ 0 1 2 3 4 5 So if you wanted "Y", you could just type "PYTHON"[1] (always start counting from 0!) """ fifth_letter = "MONTY"[4] print (fifth_letter) # In[5]: # 05 문자열 메소드(Strign Methods) parrot = "Norwegian Blue" print (len(parrot)) # In[6]: # 06 lower() 메소드 parrot = "Norwegian Blue" print (parrot.lower()) # In[7]: # 07 upper() 메소드 parrot = "norwegian blue" print (parrot.upper()) # In[8]: # 08 str() 메소드 """Declare and assign your variable on line 4, then call your method on line 5!""" pi = 3.14 print (str(pi)) # In[9]: print( type(1) ) print( type(1.)) print( type(print) ) print( type("hello")) print( type(str(1.))) # In[10]: # 09 점(.)과 문자열 함수 ministry = "The Ministry of Silly Walks" print (len(ministry)) print (ministry.upper()) # In[11]: # 10 문자열 출력 (Printing Strings) print ("Monty Python") # In[12]: # 11 변수(Variables) 출력하기 the_machine_goes = "Ping!" print(the_machine_goes) # In[13]: # 12 문자열 합치기(String Concatenation) # Print the concatenation of "Spam and eggs" on line 3! print ("Spam " + "and " + "eggs") # In[14]: # 13 명시적 문자열 변환(Explicit String Conversion) print ("The value of pi is around " + str(3.14)) # In[15]: # 14 %를 이용한 문자열 포맷팅(String Formatting), #1 string_1 = "Camelot" string_2 = "place" print ("Let's not go to %s. 'Tis a silly %s." % (string_1, string_2)) # In[16]: # 15 %를 이용한 문자열 포맷팅(String Formatting), #2 name = input("What is your name?") quest = input("What is your quest?") color = input("What is your favorite color?") print ("Ah, so your name is %s, your quest is %s, " \ "and your favorite color is %s." % (name, quest, color)) # In[17]: # 16 이제는 친숙한 내용들 my_string = "xuruiqi" print( len(my_string) ) print( my_string.upper() )