当前位置: 移动技术网 > IT编程>脚本编程>Python > python学习_1

python学习_1

2019年03月11日  | 移动技术网IT编程  | 我要评论

九江信息港乐透游戏,忍者生涯,飞翔篮球梦txt

1.python2和python3

从宏观上讲,python2源码不标准、混乱、重复,和龟叔的理念背道而驰。

在python3上,实现了源码的统一化和标准化,去除了重复的代码。

 

2.编译型语言和解释型语言

编译型:一次性将所有的程序编译成二进制文件。

    优点——运行速度快

    缺点——开发效率低,跨平台性较弱。

解释型:源码直接放在虚拟机上跑,一行一行进行执行。

    优点——开发效率高,跨平台性较强。

    缺点——运行速度相对编译型语言慢。

 

3.python在命令行上的运行

python 文件路径/xx.py

 

4.修改python的默认编码方式

python2默认ascii编码

python3默认utf-8编码

修改默认编码方式:在顶行加入“#-*- encoding:utf-8 -*-”

1 # -*- encoding:utf-8 -*-
2 print("hello, world!")

 

5.python中的变量和常量

变量:将代码中的中间结果暂时地存放在内存中,方便后续代码调用。

变量名规则:

  1.变量名由且只由数字、字母和下划线组成,且不能由数字开头。

  2.变量名不能是python中的关键字。

  3.变量要具有可描述性。

  4.尽量不能是中文。

 

常量:代码中不变的量。

python中没有正真的常量,但是可以通过将变量名改为全大写,说明这是个常量。

1 country = "china"

 

6.python中的注释

注释可以提醒别人和自己,方便理解代码。

单行注释:# 内容

多行注释:"""内容"""

     '''内容''''

 

7.基础数据类型

整型:int

  常用运算符——   +  -  *  /  **(次方)  %(取余)

字符串:str

  引号(单和双)引起来的都是字符串。

  字符串可相加、可数乘

1 print("hello,"+"world!") # 输出:hello,world!
2 print("a"*8)        # 输出:aaaaaaaa

 

8.条件控制语句if

1.if

1 if true:
2     print("hello, world!")

2.if-else

1 if 3 > 4 :
2     print("yes")
3 else:
4     print("no")

3.if-elif-else

1 flag = input("请输入1或2或3:")
2 if flag == '1':
3     print(1)
4 elif flag == '2':
5     print(2)
6 elif flag == '3':
7     print(3)
8 else:
9     print("error")

4.嵌套

1 if 3 < 4:
2     if 1 > 2:
3         print(1)
4     else:
5         print(2)
6 else:
7     print(3)

 

9.循环while

1.while格式

1 while 条件:
2     循环体

2.break

直接跳出循环

1 while true:
2     print('222')
3     print(333)
4     break
5     print(444)

3.continue

直接开始下次循环

1 count = 0
2 while count <= 100 : 
3     count += 1
4     if count > 5 and count < 95: 
5         continue 
6     print("loop ", count)

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网