Python学习笔记(1)

☞鱼丶鱼 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()--------------------------------->去除字符串中处于 两端 的空格

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值