Python学习一:变量(命名、字符串、数字、注释)

在这里插入图片描述

命名

  • 变量名只能包含字母、数字和下划线。变量名可以字母或下划线打头,但不能以数字打
  • 变量名不能包含空格,但可使用下划线来分隔其中的单词。
  • 不要将Python关键字和函数名用作变量名,
  • 变量名应既简短又具有描述性
  • 慎用小写字母l和大写字母O,因为它们可能被人错看成数字1和0。

字符串

引号
  • 用引号括起的都是字符串,其中的引号可以是单引号,也可以是双引号
  • 通过同时使用"" ‘’,或者(例如str的内容为’,表示方法为"’"或者’’’)
修改大小写
  • a.title() :以首字母大写的方式显示每个单词,即将每个单词的首字母都改为大写
  • a.upper():单词的每个字母改为大写
  • a.lower():单词的每个字母改为小写
合并(拼接)
  • 使用‘+’
添加空白
  • 在编程中,空白泛指任何非打印字符,如空格、制表符和换行符。
  • \n:换行
  • \t:制表符
删除空白
  • a.strip():删除字符串a首尾空白
  • a.rstrip():删除字符串a末尾空白
  • a.lstrip():删除字符串a开头空白

数字

整数
  • 运算:+ - * / ; 乘方:**(3 **2=9)
浮点数
  • 浮点数运算后包含的小数位数是不确定的
str(num)
  • 非字符串值表示为字符串

注释

-#
内容
  • 阐述代码要做什么,以及是如何做的。

python之禅

在终端输入import this
你会看到关于python之禅

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值