码迷,mamicode.com
首页 > 其他好文 > 详细

变量和简单数据类型

时间:2019-01-10 21:50:43      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:ref   you   last   gre   mes   ever   unless   most   类型   

变量:

  1.只能包含字母、数字和下划线。字母和下划线开头;

  2.不能包含空格;

  3.不要将关键字和函数名做变量名;

  4.简短有描述性;

  5.慎用小写字母l(L)和大写O

错误代码:
message = "Hello,Python World!" print(mesage)
Traceback (most recent call last):
  File "hello_world.py", line 2, in <module>  #文件hello_world.py的第2行存在错误
    print(mesage)
NameError: name mesage is not defined  #名称错误:mesage未定义
name = "ada lovelace"
print(name.title()) #title()是方法,大写单词首字母,方法是python可对数据执行的操作,每个方法后都有括号
Ada Lovelace

name = "ada lovelace"
print(name.upper()) #将字符串改为大写
ADA LOVELACE

name = "Ada LOVElace"
print(name.lower()) #将字符串改为小写
ada lovelace
rstrip() #临时删除右边空白,需改变,要保存
lstrip() #临时删除左边空白,需改变,要保存
strip() #临时删除两边空白,需改变,要保存
 

 

>>> 0.1+0.1
0.2
>>> 0.2+0.2
0.4
>>> 2*0.1
0.2
>>> 2*.02
0.04
>>> 0.2+0.1
0.30000000000000004  #需要注意,结果包含的小数可能是不确定的;
>>> 3*0.1
0.30000000000000004  #需要注意,结果包含的小数可能是不确定的;

注释符号 #

python之禅

>>> import this
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 arent 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 youre Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, its a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- lets do more of those!

 

变量和简单数据类型

标签:ref   you   last   gre   mes   ever   unless   most   类型   

原文地址:https://www.cnblogs.com/leisurelyRD/p/10251617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!