Skip to content

Instantly share code, notes, and snippets.

@banyan
Created February 11, 2010 01:07
Show Gist options
  • Select an option

  • Save banyan/301076 to your computer and use it in GitHub Desktop.

Select an option

Save banyan/301076 to your computer and use it in GitHub Desktop.
# ある値を文字列にしたい時は str() か repr() を使う
# str() 関数は引数で与えた値を人間が読みやすい文字列に、
# repr()関数は引数で与えた値と等価な値を返すインタプリタ表現(リテラル表記)を文字列として返す
list = ['a', 1, [1, 2, 3]]
print list # => ['a', 1, [1, 2, 3]]
print str(list) # => ['a', 1, [1, 2, 3]]
print repr(list) # => ['a', 1, [1, 2, 3]]
s = 'Hello! World!'
print s # => Hello! World!
print str(s) # => Hello! World!
print repr(s) # => 'Hello! World!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment