Python基础以及他的基本语法

  1. 运行Python
    方式一:Python交互模式
    步骤:cmd + 回车
    输入:pyhon
    输入:print(“hello world”)
    回车
    退出:exit()
    在这里插入图片描述

  2. 方式二:集成开发环境
    步骤: print(“hello world”)在这里插入图片描述

  3. 方式三 命令行执行脚本
    步骤 python+脚本
    案例 pythin hello.py在这里插入图片描述

  4. Python中的基本语法
    变量的定义 Python
    变量名 = 值
    name = 张三
    查看变量类型
    print(type(name))
    在这里插入图片描述

  5. 标识符
    开发人员在程序中自定义的一些符号和名称
    标识符是自己定义的,如变量名 、函数名

标识符的命名规则
. 标识符只能由字母、下划线“_”、数字组成。
. 标识符不能以数字开头。
. 标识符不能使用关键字
. 标识符对大小写敏感。
(建议:标识符命名应“见名知意”)

关键字
[‘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’]
标识符符合规则
if name and my_list my_list1 from#1 age 2list as True
wetyui height my_log qwe&qwe

标识符的命名方法
小驼峰:addName
大驼峰:AddName

  1. Python的输入和输出
    输入:input(“提示信息:”)
    输出:print(“输出的是:”)
    换行:/n
    在这里插入图片描述7. 格式化输出
    方式一:使用百分号(%)字符串格式化
    print(“my name is %s, and my age is %d” %(name,age))
    在这里插入图片描述

  2. print(“my name is {}, and my age is {}”.format(age,name))
    在这里插入图片描述

  3. 注释
    在这里插入图片描述

  4. 运算符
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

在这里插入图片描述
如果x为false,x and y返回x值 否则返回y的计算值
在这里插入图片描述
X是true,返回x的值,否则它返回y的计算值
在这里插入图片描述
如果X为true 返回false 如果false 如果x为false它返回true
在这里插入图片描述
11. 数据类型
Number(数字)
String(字符串)
List(列表)
Tuple(元组)
Set(集合)
Dictionary(字典)
六者的关系
不可变数据(3 个):Number(数字)、String(字符串)、Tuple(元组);
可变数据(3 个):List(列表)、Dictionary(字典)、Set(集合)。

猜你喜欢

转载自blog.csdn.net/weixin_44826661/article/details/123999311
今日推荐