1.

brian = "Hello life!"


2. 문자열 변수 할당 및 출력

# Assign your variables below, each on its own line!


caesar = "Graham"

praline = "John"

viking = "Teresa"


# Put your variables above this line


print caesar

print praline

print viking


3. 특문은 역슬래시

'This isn\'t flying, this is falling with style!'


4. index starts from 0

string = "MONTY"

fifth_letter = string[4]


print fifth_letter


5. 문자열 길이 함수

parrot = "Norwegian Blue"

print len(parrot)


6. 문자열 함수 사용법 - 뭔가 문자열 객체에다가 점 찍어서 관련 함수를 사용하는 듯

parrot = "Norwegian Blue"

print parrot.lower()

print parrot.upper()


7.  문자열로 변환하는 함수

pi = 3.14

print str(pi)


8. dot notation 사용 주의

ministry = "The Ministry of Silly Walks"


print len(ministry)

print ministry.upper()


9. print string

print "Monty Python"


10. 문자열 변수 출력하기

the_machine_goes = "Ping!"

print the_machine_goes


11. string concatenation

print "Spam " + "and " + "eggs"

print "The value of pi is around " + str(3.14)


12. 문자열 포맷 지정자: %s 로 큰 따옴표 내에서 문자열 대치할 수 있음 

    대치되는 문자열 변수들은 큰 따옴표 뒤에 %(변수 나열)  식으로 해서 넣음

    "문자열 %s" %(string)

name = raw_input("What is your name?")  #문자열 입력 받아오는 함수 with comment

quest = raw_input("What is your quest?")

color = raw_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)


13.

my_string = "Keol Cho"

print len(my_string)

print my_string.upper()




'Python' 카테고리의 다른 글

functions  (0) 2016.02.08
Pig Latin  (0) 2016.02.08
Conditional and control flow  (0) 2016.02.05
datetime library  (0) 2016.02.04
python 걸음마 시작  (0) 2016.02.02

끼적거리다가 본격적으로 연습 시작.

최종 목표는 LDPC decoder 시뮬레이터 여러 방법으로 실행하기


https://www.codecademy.com/learn/python


1.

print "Welcome to Python!"


2. 변수, 숫자

# Write your code below!

my_variable = 10


3. 변수, 실수, 불리언

my_int = 7

my_float = 1.23

my_bool = True


4. 변수 재 어사인

my_int = 7

# Change the value of my_int to 3 on line 8!

my_int =3

print my_int


5. python 에서 공백은 code structure 에 영향을 줌, space 나 tab 으로 indentation 함으로써 코드 구성 가능

def spam():

 eggs = 12

 return eggs

        

print spam()


6. interpreter 이해

spam = True

eggs = False


7. python 에서의 comment 는 #

#this is comment for python

mysterious_variable = 42


8. multi-line comment 는 큰따옴표 세 개 사이에 넣기

"""multi line comment

comment

comment

"""


9. 산술연산 ; 덧셈

# Set count_to equal to the sum of two big numbers

a_big = 1000000

b_big = 20102301


count_to = a_big+b_big


print count_to


10. 지수승은 ** 

eggs = 10**2


print eggs


11. 모듈로 연산은 똑같음 %

spam =5%4

print spam


12. 종합

# all together

monty = True

python = 1.234

monty_python = python**2



13. meal 계산

# Assign the variable total on line 8!


meal = 44.50

tax = 0.0675

tip = 0.15


meal = meal + meal * tax


total = meal + meal*tip

print("%.2f" % total)

'Python' 카테고리의 다른 글

functions  (0) 2016.02.08
Pig Latin  (0) 2016.02.08
Conditional and control flow  (0) 2016.02.05
datetime library  (0) 2016.02.04
string  (0) 2016.02.02

+ Recent posts