python学习入门(一)
第一行python代码
1 message = 'hello python world' 2 print(message) 3 message = 'I love Lina' 4 print(message)
使用title函数首字母大写的方式显示每一个单词
1 name = "i lovE Ling" 2 print(name.title())
使用upper函数将字符串全部改为大写
1 up_str = "i love Ling" 2 print(up_str.upper())
使用lower函数将字符串全部改为小写
1 low_str = "I Love Ling" 2 print(low_str.lower())
使用‘+’拼接字符串
1 first_name = "Li" 2 last_name = "JinLing" 3 full_name = first_name + " " + last_name 4 message = "Hello " + full_name + " !" 5 print(message)
使用rstrip函数删除字符串结尾多余的空白
1 space_str = " I Love Ling " 2 print(space_str.rstrip())
使用lstrip函数删除字符串开头多余的空白
1 print(space_str.lstrip())
使用strip函数删除字符串两端多余的空白
1 print(space_str.strip())
使用str函数避免类型错误
1 age = 23 2 message = "Happy " + str(age) + "rd birthday" 3 print(message)
原文转自:https://blog.csdn.net/fzx1123/article/details/86099263
如侵必删

浙公网安备 33010602011771号