上一篇文章介绍了Python学习中需要的一些基础知识,今天继续介绍几个知识点:
1.代码中的注释
注释是编程语言的一个重要组成部分,用于在源代码中解释代码的作用,从而增强程序的可读性与可维护性。当然在调试程序时,也需要用到注释,注释在编译时会被编译器忽略,不会在目标代码中保留也不会影响代码的执行结果。
Python中代码注释有两种方法:
1.单行注释:以#开头的部分
2.多行注释:三个引号开头,三个引号结尾
'''
作者:等等登登
邮箱:18356768364@163.com
'''
print('hello world!!!')
#print('你好,世界')
2.Python中的运算符
Python支持多种运算符,下表大致按照优先级从高到低的顺序列出所有运算符:
运算符 | 描述 |
[ ],[ : ] | 下标、切片 |
** | 指数 |
~ ,+,- | 按位取反、正负号 |
*,/,%,// | 乘、除、取模、整除 |
+,- | 加、减 |
<<,>> | 左移、右移 |
& | 按位与 |
^,| | 按位异或、按位或 |
<=,<,>,>= | 小于等于、小于、大于、大于等于 |
==,!= | 等于、不等于 |
is,is not | 同一性运算符 |
in,not in | 成员运算符 |
not,or,and | 逻辑运算符 |
=,>>=,<<=,+=,-=,*=,/=,%=,//=,**=,&=,|=,^= | 赋值运算符 |
3.函数库的引用
Python中的外部函数库包括:
1、包含在安装包中的函数库:如turtle、math等
2、其他外部函数库:如numpy、pandas等(根据自己的需要安装相应的外部函数库)
Python对外部函数库的引用很简单,主要有两种方法:
①import 库名:如import numpy、import turtle
import turtle
turtle.pensize(3)
turtle.pencolor('red')
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.left(90)
turtle.mainloop
②for <库名> import <函数名> 或者from <库名> import *
from turtle import *
turtle.pensize(3)
turtle.pencolor('red')
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.left(90)
turtle.mainloop