笔记:
全局函数:
print(字符串) 将字符串直接输出控制台上
input() 将用户的信息从控制台上读取到代码中
int()
str()
python的书写规范
每一行代码写完之后换行,\n换行符是python语句结束的标识符
注意:;也可以使用,但是不推荐
变量的命名规范:
标识符的命名规范:
标识符:程序中用来描述一些事物的名称
1、标识符只能由数字、大小写字母、_这三种有效符号组成,注意:Python中$不是有效符号
2、数字不能开头!!!
3、不能以关键字或者保留字作为标识符
4、不要使用系统已经在全局定义好的变量或者函数名称
5、建议标识符命名有意义
6、一般建议大家使用_或者小驼峰
findUserGroupByUsername
find_user_group_by_username[店家推荐]
7、特殊情况:
1、类名称使用大驼峰法
UserAddress
2、python没有专门用来定义常见的关键字,是使用变量,所有单词都是大写就是常量
PI = 3.14
NAME = "china"
TIME = "UTC
python的关键字:
import keyword
keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await',
'break', 'class', 'continue', 'def', 'del', 'elif', 'else',
'except', 'finally', 'for', 'from', 'global', 'if', 'import',
'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise',
'return', 'try', 'while', 'with', 'yield']
python的全局函数:
import builtins
dir(builtins)
'abs', 'aiter', 'all', 'anext', 'any', 'ascii', 'bin', 'bool', 'breakpoint',
'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex',
'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate',
'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr',
'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int',
'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals',
'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord',
'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed',
'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod',
'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip'
python数据类型
基本数据类型
数值型(number)
|-- int 整型
|-- float 浮点型
|-- complex 复数|虚数
布尔类型(bool)
True
False
字符串(str)
"字符串"
'字符串'
""" 字符串 """
''' 字符串 '''
复合数据类型
万物皆对象
list
set
tuple
dict
object
……
数据类型转换:
自动类型转换
整型 浮点型 布尔类型
强制类型转换
int(字符串)
float(字符串)
str(值)
import os
os.system("command")
常见的运算符
算术运算符:
+
-
*
/
// 整除
%
** 幂次方
关系运算符
>
<
>=
<=
== <>
!=
逻辑运算符
and
or
not
所属运算符
in
not in
is运算符
is运算符比较两个变量的内存地址
==比较两个变量的值
is
is not
赋值运算符
=
+= # a += 1 a = a + 1
-=
*=
/=
//=
%=
**=
注意:python没有自加和自减运算符,可以使用赋值运算符完成
三目运算符
像C、java、js等编程语言中:
变量 = 表达式 ? 值1 :值2
python的三目运算符
变量 = 值1 if 表达式 else 值2
作业:
c