# 01 문자열(Strings)
brian = "Always look on the bright side of life!"
# 02 연습(Practice)
caesar = "Graham"
praline = "John"
viking = "Teresa"
print(caesar)
print(praline)
print(viking)
Graham John Teresa
# 03 이스케이프 문자(Escaping characters)
'Help! Help! I\'m being repressed!'
"Help! Help! I'm being repressed!"
#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)
Y
# 05 문자열 메소드(Strign Methods)
parrot = "Norwegian Blue"
print (len(parrot))
14
# 06 lower() 메소드
parrot = "Norwegian Blue"
print (parrot.lower())
norwegian blue
# 07 upper() 메소드
parrot = "norwegian blue"
print (parrot.upper())
NORWEGIAN BLUE
# 08 str() 메소드
"""Declare and assign your variable on line 4,
then call your method on line 5!"""
pi = 3.14
print (str(pi))
3.14
print( type(1) )
print( type(1.))
print( type(print) )
print( type("hello"))
print( type(str(1.)))
<class 'int'> <class 'float'> <class 'builtin_function_or_method'> <class 'str'> <class 'str'>
# 09 점(.)과 문자열 함수
ministry = "The Ministry of Silly Walks"
print (len(ministry))
print (ministry.upper())
27 THE MINISTRY OF SILLY WALKS
# 10 문자열 출력 (Printing Strings)
print ("Monty Python")
Monty Python
# 11 변수(Variables) 출력하기
the_machine_goes = "Ping!"
print(the_machine_goes)
Ping!
# 12 문자열 합치기(String Concatenation)
# Print the concatenation of "Spam and eggs" on line 3!
print ("Spam " + "and " + "eggs")
Spam and eggs
# 13 명시적 문자열 변환(Explicit String Conversion)
print ("The value of pi is around " + str(3.14))
The value of pi is around 3.14
# 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))
Let's not go to Camelot. 'Tis a silly place.
# 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))
What is your name?plusjune What is your quest?run What is your favorite color?red Ah, so your name is plusjune, your quest is run, and your favorite color is red.
# 16 이제는 친숙한 내용들
my_string = "xuruiqi"
print( len(my_string) )
print( my_string.upper() )
7 XURUIQI