标签:变量 表示 首字母 单词 引用 blog one and variable
name = ‘hand tech‘ print(name.title()) >> Hand Tech
print(name.upper()) >>HAND TECH print(name.lower()) >> hand tech
print(‘This is my‘ + ‘ first Python program!‘) >> This is my first Python program!
print(‘hello‘ + 2 + ‘ world‘) Traceback (most recent call last): File "<pyshell#14>", line 1, in <module> print(‘hello‘ + 2 + ‘ world‘) TypeError: must be str, not int >>
print(‘hello ‘ + str(2) + ‘ world‘)
>>hello 2 world
>>> print("\tPython") Python >>> print("Language:\n\tPython\n\tC\n\tJavaScript") Language: Python C JavaScript
>>> favorite_language = ‘python ‘ >>> favorite_language ‘python ‘ >>> favorite_language.rstrip() ‘python‘ >>> favorite_language ‘python ‘
方法:rstrip() 删除字符串右边空格
message = ‘One of python‘s strengths is its diverse community.‘ print(message)
>>> 3 ** 2 9 >>> 3 ** 3 27 >>> 10 ** 6 1000000
age = 23 message = "Happy " + age + " rd Birthday!" print(message)
mesasge = "Happy " + str(age) + " rd Birthday!"
标签:变量 表示 首字母 单词 引用 blog one and variable
原文地址:http://www.cnblogs.com/objmodel/p/7655256.html