Python编程从入门到实践笔记——变量和简单数据类型
#coding=gbk #变量 message_1 = 'aAa fff' message_2 = 'hart' message_3 = "Albert Einstein once said, “A person who never made a mistake never tried anything new.”" #使用方法修改字符串的大小写 print(message_1.title()) print(message_1.upper()) print(message_1.lower()) #字符串拼接 print(message_1+" "+message_2) #使用制表符或换行符来添加空白 print(" Python") print("Python Java JavaScript") #删除空白 #删除字符串末尾空白rstrip() #删除字符串开头的空白lstrip() #删除字符串两端的空白strip(),效果等于Java中的trim() favorite_language=' python ' print("My favorite language is "+favorite_language.rstrip()+".") print("My favorite language is "+favorite_language.lstrip()+".") print("My favorite language is "+favorite_language.strip()+".") #字符串替换 a='Hello World' b=a.replace('World','Python') #整数 num=23 print(num) #**表示乘方运算 print(num**2) #浮点数 num_1=0.1 print(num_1*2) #使用str()避免类型错误 print(str(23)+"james")