当前分类:python>>正文

了解Python语言核心知识,实现高效的编程

来源:互联网   更新时间:2023年7月29日  

Python 笔记

一、基本语法

if 5 > 2:
    print("Hello, World!")

二、数据类型

a = 18
b = 3.14
c = "Hello, World!"
d = True
e = [1, 2, 3, 4, 5]
f = (1, 2, 3, 4, 5)
g = {"key1": "value1", "key2": "value2"}

print(type(a)) # 
print(type(b)) # 
print(type(c)) # 
print(type(d)) # 
print(type(e)) # 
print(type(f)) # 
print(type(g)) # 

三、函数

def add_numbers(a, b):
    return a + b

result = add_numbers(2, 3)
print(result) # 5

四、对象与类

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age
    
    def say_hello(self):
        print("Hello, my name is", self.name, "and I am", self.age, "years old.")

p = Person("John", 30)
p.say_hello() # Hello, my name is John and I am 30 years old.
本文固定链接:https://6yhj.com/leku-p-5117.html  版权所有,转载请保留本地址!
[猜你喜欢]

标签: css