一、运行python程序
1.文件.py后缀表明文件类型,编辑器会用python解释器来运行该文件,python解释器读取全部程序确定没一个单词的含义进行运行

二、变量
1.变量内容代表所关联的信息,变量关联信息可以在程序中随时更改,python会始终记录每个变量最新的关联信息
代码如下:
`
msg = "first value"
print(msg)

msg = "second value"
print(msg)
`
运行结果:
first value
second value

2.变量命名规则
<1>变量名只能包含字母、数字、下划线,且开头仅能为字母或下划线
<2>变量名不能包含空格
<3>变量名不能包含python关键字
<4>变量名应简短且具有描述性
<5>变量名尽量避免使用字母i和O
<6>变量名尽量少使用大写字母

3.变量名务必保持程序中使用到的时候变量名拼写正确,当出现变量未赋值或变量名拼写不正确时,python解释器会返回一个traceback,这是一条记录反应解释器尝试运行程序时遇到的问题,一般包含以下三部分:
<1>报错文件及报错代码行数
<2>报错代码内容
<3>报错信息

4.练习题
<1>将一条消息存储在变量值并打印
msg = "The first message" print(msg)
<2>将 <1>中变量存储新的消息再次打印
msg = "The first message" print(msg) msg = "The new message" print(msg)

三、字符串
1.由双引号或单引号括起来的数据内容就是字符串

2.使用方法改变字符串大小写
python中的方法:方法是对数据可进行的操作,在变量后加点(.),python解释器会根据点(.)后的方法对数据进行处理,方法名后都带有括号,以传递更多的参数,当不需要更多参数时,括号内为空

.title():字符串中单词首字母大写,同时将非首字母小写
.upper():字符串所有字母大写
.lower():字符串所有字母小写

3.制表符和换行符
制表符:\t
换行符:\n

4.删除空格
删除字符串开头空格:.lstrip()
删除字符串末尾空格:.rstrip()
删除字符串开头及末尾空格:.strip()

5.单双引号使用
字符串中包含瞥时,应使用双引号括起字符串

6.练习

三、数字
1.整数(加减乘除)
2.浮点数(加减乘除)
不懂?

3.转为字符串
str(variable)

4.练习

四、python之禅
import this:
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!