python字串格式化

來源:互聯網
上載者:User

標籤:python   字串   

Python 2.7.12rc1 (v2.7.12rc1:13912cd1e7e8, Jun 12 2016, 05:57:31) [MSC v.1500 64 bit (AMD64)] on win32Type "copyright", "credits" or "license()" for more information.>>> str1="i love fish">>> str1[:6]‘i love‘>>> str="111eee">>> str.isalnum()True>>> str6="i love cppc">>> str‘111eee‘>>> str6‘i love cppc‘>>> str6.splice()Traceback (most recent call last):  File "<pyshell#7>", line 1, in <module>    str6.splice()AttributeError: ‘str‘ object has no attribute ‘splice‘>>> str6.split()[‘i‘, ‘love‘, ‘cppc‘]>>> str6‘i love cppc‘>>> str6.title()‘I Love Cppc‘>>> "{a} love {b}.{c}".format(a=‘i‘,b=‘fish‘,c=‘com‘)‘i love fish.com‘>>> {0}.format("ni")Traceback (most recent call last):  File "<pyshell#12>", line 1, in <module>    {0}.format("ni")AttributeError: ‘set‘ object has no attribute ‘format‘>>> "{0}".format("ni")‘ni‘>>> {{0}}.format("ni")Traceback (most recent call last):  File "<pyshell#14>", line 1, in <module>    {{0}}.format("ni")TypeError: unhashable type: ‘set‘>>>  "{{0}}".format("ni")   File "<pyshell#15>", line 2    "{{0}}".format("ni")    ^IndentationError: unexpected indent>>> "{}".format("ni")‘ni‘>>> "{{0}}".format("ni")‘{0}‘>>> "{0:.1lf}{1}".format(27.546,GB)Traceback (most recent call last):  File "<pyshell#18>", line 1, in <module>    "{0:.1lf}{1}".format(27.546,GB)NameError: name ‘GB‘ is not defined>>> "{0:.1lf}{1}".format(‘27.546‘,‘GB‘)Traceback (most recent call last):  File "<pyshell#19>", line 1, in <module>    "{0:.1lf}{1}".format(‘27.546‘,‘GB‘)ValueError: Invalid conversion specification>>> "{0:.1lf}{1}".format(27.546,‘GB‘)Traceback (most recent call last):  File "<pyshell#20>", line 1, in <module>    "{0:.1lf}{1}".format(27.546,‘GB‘)ValueError: Invalid conversion specification>>> "{0:.1f}{1}".format(‘27.546‘,‘GB‘)Traceback (most recent call last):  File "<pyshell#21>", line 1, in <module>    "{0:.1f}{1}".format(‘27.546‘,‘GB‘)ValueError: Unknown format code ‘f‘ for object of type ‘str‘>>> ‘{0:.1lf}{1}‘.format(27.546,‘GB‘)Traceback (most recent call last):  File "<pyshell#22>", line 1, in <module>    ‘{0:.1lf}{1}‘.format(27.546,‘GB‘)ValueError: Invalid conversion specification>>> "{0:.lf}{1}".format(27.546,‘GB‘)Traceback (most recent call last):  File "<pyshell#23>", line 1, in <module>    "{0:.lf}{1}".format(27.546,‘GB‘)ValueError: Format specifier missing precision>>> "{0:.1f}{1}".format(27.546,‘GB‘)‘27.5GB‘>>> ‘%c %c %c‘ % (97,97,99)‘a a c‘>>> ‘%e‘  %  27.3342‘2.733420e+01‘>>>

650) this.width=650;" src="/img/fz.gif" alt="複製代碼" style="margin:0px;padding:0px;border:none;" />

 

650) this.width=650;" src="http://images2015.cnblogs.com/blog/730879/201611/730879-20161109000826483-1186935592.png" style="margin:0px;padding:0px;border:0px;" />

 

650) this.width=650;" src="http://images2015.cnblogs.com/blog/730879/201611/730879-20161109000807889-515814846.png" style="margin:0px;padding:0px;border:0px;" />

650) this.width=650;" src="http://images2015.cnblogs.com/blog/730879/201611/730879-20161109000818202-1297277783.png" style="margin:0px;padding:0px;border:0px;" />

 


python字串格式化

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.