將寫代碼過程經常用到的代碼片段珍藏起來,如下代碼段是關于python中數(shù)字和字符串連接的方法的代碼腺晾,應該對各位有些用途。
#!/usr/bin/env python
#
# [SNIPPET_NAME: String and number concatenation]
# [SNIPPET_CATEGORIES: Python Core]
# [SNIPPET_DESCRIPTION: Concatenate a string and a number]
# [SNIPPET_AUTHOR: Jono Bacon <jono@ubuntu.com>]
# [SNIPPET_LICENSE: GPL]
x = 1
print str(x) + " is a string"
print "%s is a string" % x
print x, "is a string"