Python學習筆記之20140406

# Time : 2014-4-6 23:39 Python學習筆記
1.Python輸出中文
#!/usr/bin/python
#coding:utf-8
2.Python %s %r的區別
The %s specifier converts the object using str(), and %r converts it using repr().

For some objects such as integers, they yield the same result, but repr() is special in that (for types where this is possible) it conventionally returns a result that is valid Python syntax, which could be used to unambiguously recreate the object it represents.

Here's an example, using a date:

>>> d = datetime.date.today()
>>> str(d)
'2011-05-14'
>>> repr(d)
'datetime.date(2011, 5, 14)'

Types for which repr() doesn't produce Python syntax include those that point to external resources such as a file, which you can't guarantee to recreate in a different context.
3.print "." * 10 以及 + 的應用
4. formatter = "%r %r %r %r"
5. \n \t 以及 """ 以及轉義字符(diffcult-to-type)\的使用
6. 輸入函數 raw_input()
發佈了40 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章