标签:enc 消息 you ndt 字符串 hello 个性 learn number
2-1简单消息:
1 #2-1 简单消息 2 mesage = ‘Hello World‘ 3 print(mesage)
注意,将变量定义为那一串字符串,字符串是需要引号扩起的
2-2多条简单消息:
#2-2 多条简单消息 mesage = ‘Hello World‘ print(mesage) mesage = ‘Goodbye World‘ print(mesage)
2-3个性化消息:
1 #2-3个性化消息 2 name = ‘Cat‘ 3 mesage = ‘Hello ‘+name+‘,would you like to learn some Python today?‘ 4 print(mesage)
2-4调整名字的大小写
1 #2-4调整名字的大小写 2 name = ‘cat‘ 3 print(name.title()) 4 print(name.upper()) 5 print(name.lower())
2-5名言:
#名言 name = ‘Albert Eindtein‘ sentence =‘said,"A person who never made a mistake never tried anything new. "‘ famoussaid=name +‘ ‘+sentence print(famoussaid)
2-6名言2:同上
2-7剔除人名中的空白:
1 #2-7剔除人名中的空白 2 famous_name =‘ cat ‘ 3 print(famous_name) 4 print(famous_name.strip()) 5 print(famous_name.lstrip()) 6 print(famous_name.rstrip())
2-8:数字8:
1 print(5+3) 2 print(1*8) 3 print(8/1) 4 print(9-1)
2-9最喜欢的数字:
1 #2-9最喜欢的数字 2 favourite_num = 3 3 message = "My favourite number is " + str(favourite_num) + "." 4 print(message)
注,调用str函数,将非字符串值表示为字符串
标签:enc 消息 you ndt 字符串 hello 个性 learn number
原文地址:https://www.cnblogs.com/cat30/p/12812594.html