「Python」Python 01 基础语法

在这里插入图片描述

① Python 基本数据类型

  • Number「int、float、bool、complex」
  • String(字符串)
  • List(列表)
    1.列表中每个元素可变;
    2.列表可存储 Python 任何对象;᨝
  • Tuple (元组)
    1.固定版本列表,元组不可修改;
  • Dictionary(字典)
    1.数据必须以键值对形式出现;
    2.键(key)不能重复,且不可变,值(Value)可变,可以是任何对象
  • sets(集合:无序,不重合的任意对象)

② Python 条件控制

age = 30
if age >= 20:
    print('Young')
elif age >= 40:
    print('Man')
else:
    print('else')

③ Python 循环

○ for 循环:
lists = ['n1', 'n2', 'n3', 'n4']
for i in lists:
    print(i)
○ While 循环
i = 0
size = 5
while i < size:
    print('i =', i)
    i += 1

④ Python 函数

函数通用格式:

def 函数名(参数列表):
  函数体

实例

def hello():
    print('Hello,Python3')
hello() # 函数调⽤

⑤ Python 类

类的继承**「Python 类可以多继承」**

⑥ Python 模块

Python 模块理解:Java 语言 包「package」 类似,使用 Import 语句导入

⑦ Python 输入输出

输出:Print()
读取键盘输入:input()

⑧ Python 文件

基本格式:

file = open(filename, mode)

文件对象方法:

file.read()
file.readline()
file.readlines()
file.close()

读取文件:

file = open('F:/install_notes_cn.txt', 'r')
for line in file.readlines():
    print(line)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值