字符串练习。
# -*- coding: utf-8 -*-"""Created on Mon Feb 20 09:43:23 2017@author: Administrator"""name='Bill gate'print(name)#对比print(name.title())#首字母大写print(name.upper())#全部大写print(name.lower())#全部小写FirstName='bill'#字符串拼接SecondName='Cat'LastName='gate'fullname=FirstName+' '+LastNameprint(fullname)print('Hello,'+fullname+'.')print('\tPython')print('动态脚本语言:'+'Java\tPHP\tASP.')print('Python\nPerl\nRuby')print('Language:\n\tPython\n\tC\n\tJavascript')favoritelanguage='Python language'print(favoritelanguage)text1='hello 'print(text1,len(text1))text2=text1.rstrip();print(text1.rstrip(),len(text2))#去除单词末尾空格text3=' dnf 'print(text3.rstrip(),len(text3))print(text3.lstrip(),len(text3))print(text3.strip(),len(text3))print(4**0.5,0.7777+.011111111111111111111111,7.11-0.33333,3*0.1,0.1+0.2,0.3/2,3.0/2.0)age='22'message='Happy '+str(age)+'rd Birthday.'print(message)#单行注释'''多行注释'''nulltuple=()newtuple=tuple({1,2,3,4,5,6})print(newtuple)
注意:Python 字符串中空格会完全保留,某些编程语言只会保留一个空格。