☞鱼丶鱼 2019 年 11 月 13日
(又双十一了,冲鸭)
平台:Python 3.7.4
一、输出格式(Python 3 和 Python 输出方式略有不同,以下为Python 3 的全部输出格式)
1、print 的用法
print(’–字符串空格–’)
print(‘hello world!’) #字符串也包含“ ”空格
print(‘hello’,‘world!’) #逗号用于空格字符串间的
print() #表示空一行
print(’–字符串拼接–’)
print(‘hello’‘world!’) #字符串间默认拼接
print(‘hello’+‘world!’) #加号用于字符串间拼接
print()
print(’–print中\n换行–’) #用\n前用\表示转义
print(‘abc’)
print(‘a\nb\nc’)
print(’----------’) #表示分隔符
print(’–print中的用法–’)
print(‘3’ * 5) #print中字符用号表示字符重复多少次
print(3 * 5) #print中数字用*号表示求积算法
print(’----------’)
print(’–print中end的用法–’)
print(‘Nothing is impossible to a willing heart!’) #字符默认是换行的
print(‘Nothing is impossible to a willing heart!’, end=’’) #end=’‘表示不换行,单引号内没有空格的
print(‘Nothing is impossible to a willing heart!’, end=’\n’) #end=’\n’和\n都是换行
print(’----------’)
print(’–print中的sep表示两单词间用什么字符分隔–’)
print(‘hello’,‘world’, sep=’***’)
print(“file\n”,“abc”,“fff”,sep=’###\n’) #换行间的字符串间也会被“###”分隔
2、空格和换行
可以放在一起用:
\t---------------------------------------->添加在字符串中可设置数目的空格
eg:print("\tHello")
\n---------------------------------------->换行
eg:print("\nname:\nchen\hao")
3、单引号、双引号的区别
使用单引号和双引号的效果是一样的,如果想输出带有符号的内容,需要再放进一对单引号中:
4、常用操作变量的方法:
变量名.title()------------------------------->将变量中每个单词以首字母大写输出
变量名.lower()------------------------------->将变量中每个单词以首字母大写输出
变量名.rstrip()--------------------------------->去除字符串中处于 最后 的空格
变量名.lstrip()--------------------------------->去除字符串中处于 开头 的空格
变量名.strip()--------------------------------->去除字符串中处于 两端 的空格