python基础语法
发布日期:2021-05-10 03:36:37 浏览次数:6 分类:精选文章

本文共 4275 字,大约阅读时间需要 14 分钟。

1������������������

���1������������������

���Python������print() ������������������������������������������������������������������������������������������������������������������������������������������������������������������

���������

print(1+2)  # ������: 3

���2������������������

������������������������������������������������������������������������������������������ ' '������������������������������������������������������������������������

���������

print('������������������������')  # ������: ������������������������

���3������������������

������������������������������ " ������������������������������������������������������������������������������������������������

���������

print("Let���s go go go")  # ������: Let���s go go go

���4���������������������

���������������������������������������������������������������������������������������������������������������������������������������������������

���������

print("Let���s go go go")  # ������: Let���s go go go

2���������������

  • ������������������������������
  • ������������������������������������������
  • ��������������������������������� 4.��������������������������������������������� 5.������������Python������������������������������
  • ���������

    number = 34
    name1 = 'kaikeba '
    list_class = ['������������', '������', '������������']

    3. Python���������������������������������������������

    ���������Python������������������������������������������������������

    • ���������������List���������������Dictionary���������������Set������������
    • ������������������Number���������������String������������������Tuple������������

    4. Python������������

    • ��������� \���������������������������
    • ������\������������������������������

    5. Python������������

    Numbers������������

    • int��������������� -123, 456, 789
    • float������������������ 3.1415
    • bool���������������������True���False

    String���������������

    • ��������������� ' ������������ " ���������������������
    • ������������������ + ������
    • ���������������������������������������

    List������������

    • ������������ [] ������
    • ���������������������������
    • ���������������������������

    Tuple������������

    • ������������ () ������
    • ���������������������������������������������
    • ���������������������������������������

    Set������������

    • ������������ {} ������
    • ������������������
    • ���������������

    Dict������������

    • ������������ {} ������
    • ������������������������������
    • ���������

    6. ������������������

    f-string������������������������

    • ��� f ������
    • ������������������������������������
    • ���������
    name = '������'
    age = 24
    print(f'Hello, {name} {age}') # ������: Hello, ������ 24

    at-string���@-���������������������

    • ������ @ ���������������������
    • ���������
    print(f'Hello, {name}') == f'Hello, {name}'

    7. ������������

    Python���������������������������������������������������������������

    • input()���������������������
    • open()���������������
    • write()���������������
    • read()���������������������

    8. ������������

    ������ try-except-finally ������������������������

    try:
    with open('file.txt', 'r') as f:
    print(f.read())
    except FileNotFoundError:
    print('���������������')
    finally:
    print('������������������')

    9. ������������

    ���������

    class Person:
    def __init__(self, name, age):
    self.name = name
    self.age = age
    def __str__(self):
    return f'���������������{self.name}������������{self.age}'

    ���������

    p1 = Person('������', 24)
    p1.__str__()

    10.������������������

    class Animal:
    def __init__(self):
    self.name = '������'
    class Dog(Animal):
    def __init__(self):
    super(Dog, self).__init__()
    self.breed = '���'
    def __str__(self):
    return f'{self.name}���������{self.breed}'

    11.������������

    ���Python������������������������������ raise ���������

    class CustomError(Exception):
    pass
    # ������������
    raise CustomError("������������")
    # ������������
    try:
    raise CustomError("������������")
    except CustomError as e:
    print(e.args)

    12.������������

    for������

    students = ['������', '������', '������']
    for student in students:
    print(student)

    while������

    n = 2
    while n <= 3:
    print(n)
    n += 1

    13.������������

    ������������������ def ������������������ class ���������������������������������������������������������������

    14.������������������

    ���������������������������������������������

    • int()
    • float()
    • str()
    • list()
    上一篇:Java泛型详解
    下一篇:Java中的递归操作

    发表评论

    最新留言

    表示我来过!
    [***.240.166.169]2025年04月15日 09时50分13秒

    关于作者

        喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
    -- 愿君每日到此一游!

    推荐文章