python知识体系第一节——python入门

1 Python介绍、特性、版本问题、应用范围**

1.1 介绍

1989年发明、1991年发布,解释型、面向对象的语言。
官网:www.python.org.

1.2 特性

可读性强、简洁、面向对象、免费和开源、可移植性和跨平台、
丰富的库、可扩展性(可嵌入到C/C++)。python是由C语言开发
螺旋线代码:

import turtle
t=turtle.Pen()
for x in range(360):
	t=fooward(x)
	t=left(50)
	

1.3 版本问题

python2已经2020即将推出历史舞台,现在都使用python3.x

1.4 应用范围

科学计算、人工智能、WEB服务端和大型网络后端、
GUI开发(图形用户界面开发)、游戏开发、移动设备、
嵌入式设备、系统运维、大数据、云计算

2 Python程序格式、缩进、行注释、段注释**

2.1 程序格式

缩进用4个空格或Tab表示,用来代表程序块,python中不需要各程序块不需要使用{}来表示,
而是直接使用空格,并且每条程序都需要占用单独的一行,

2.2 python区分大小写,

2.3 单行注释:

#在每行的前面加上#即可

多行注释:

'''
在这几行的开始和结尾加上三个单引号,'''
'''

3.海龟绘图:画出奥运五环图

代码一定要动手敲!!!

import turtle
turtle.width(5)

turtle.color("blue")
turtle.circle(50)

turtle.penup()
turtle.goto(120,0)
turtle.pendown()

turtle.color("black")
turtle.circle(50)

turtle.penup()
turtle.goto(240,0)
turtle.pendown()

turtle.color('red')
turtle.circle(50)

turtle.penup()
turtle.goto(60,-40)
turtle.pendown()

turtle.color('yellow')
turtle.circle(50)

turtle.penup()
turtle.goto(180,-40)
turtle.pendown()

turtle.color('green')
turtle.circle(50)

4 程序的构成

(1)python程序由多个模块构成,每一个模块都是一个.py文件,每个模块都会实现各自的功能(由各语句组成),
多个模块即构成了一个复杂的python程序。
(2)python语句的执行顺序为依次执行
(3)语句为python程序的构造单元,用于创建对象、变量赋值、调用函数、控制语句。

5 对象的基本组成和内存示意图

python中所有的东西都可以称为对象,对象包含type(类型)、标识(identity)、value(值)三个要素。
对象的本质是一个内存块,拥有特定的值,支持特定类型的相关操作。

>>> a
3
>>> print(a)
3
>>> id(a)
1658103760
>>> type(a)
<class 'int'>
>>> 

实质上所谓赋值,例如a=3,就是将3的属性传递给a,
通常所理解的a等于3仅仅只包含的大小的传递,而计算机系统中包含3个信息,所以
a=3不能仅仅理解为“大小等于”,而是属性的传递。
正是由于上述原因,使得python不需要声明变量类型,即python为动态类型语言,并且python
对数据类型很敏感,每个数据类型只支持其对应的数据类型的操作。

6 标识符、帮助系统的使用、命名规则、删除

6.1 标识符

用于标识变量、函数、类、模块,命名规则为
(1)区分大小写;
(2)名字由字母,数字,下划线构成,并且开头不能为数字
(3)关键字不能用作标识符,例如打出if后,系统会自动将其识别为关键字,当后面接等号赋值时系统会报错
(4)尽量避免使用下划线开头与结尾,例如_int_,其代表的是构造函数。
例如:
首字母为数字报错

>>> 3a=3
SyntaxError: invalid syntax

使用关键词报错

>>> if =3
SyntaxError: invalid syntax

6.2 查关键词方法

>>> help()

Welcome to Python 3.8's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at https://docs.python.org/3.8/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> keywords

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not                 

help> quit

You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)".  Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.

也可以直接打开编译器按F1

6.3 删除变量可以直接使用del

例如:

>>> a=3
>>> a
3
>>> del a
>>> a
Traceback (most recent call last):
  File "<pyshell#17>", line 1, in <module>
    a
NameError: name 'a' is not defined
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值