河北石家庄建设网站,青岛公司网站建设,南通网站优化推广,可以做问卷挣钱的网站#x1f49d;#x1f49d;#x1f49d;欢迎莅临我的博客#xff0c;很高兴能够在这里和您见面#xff01;希望您在这里可以感受到一份轻松愉快的氛围#xff0c;不仅可以获得有趣的内容和知识#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:「stormsha的主页」… 欢迎莅临我的博客很高兴能够在这里和您见面希望您在这里可以感受到一份轻松愉快的氛围不仅可以获得有趣的内容和知识也可以畅所欲言、分享您的想法和见解。 推荐:「stormsha的主页」持续学习不断总结共同进步为了踏实做好当下事儿~ 专栏导航 Python系列: Python面试题合集剑指大厂Git系列: Git操作技巧GO系列: 记录博主学习GO语言的笔记该笔记专栏尽量写的试用所有入门GO语言的初学者数据库系列: 详细总结了常用数据库 mysql 技术点,以及工作中遇到的 mysql 问题等运维系列: 总结好用的命令高效开发算法与数据结构系列: 总结数据结构和算法,不同类型针对性训练,提升编程思维 非常期待和您一起在这个小小的网络世界里共同探索、学习和成长。 ✨✨ 欢迎订阅本专栏 ✨✨ The Start点点关注收藏不迷路 文章目录 基础语法变量和数据类型控制结构函数 数据结构列表字典集合元组 面向对象编程类和对象继承 文件和异常处理文件操作异常处理 模块和包导入模块创建和使用包 网络编程使用socket 数据库操作使用SQLite 基础语法
变量和数据类型
x 10 # 整数
name Kimi # 字符串
is_active True # 布尔值控制结构
if x 5:print(x is greater than 5)
else:print(x is less than or equal to 5)for i in range(5):print(i)while x 10:x 1函数
def greet(name):print(fHello, {name}!)greet(Kimi)数据结构
列表
fruits [apple, banana, cherry]
fruits.append(orange)
print(fruits)字典
person {name: Kimi, age: 25}
print(person[name])集合
numbers {1, 2, 3, 4, 5}
unique_numbers numbers.union({5, 6, 7})
print(unique_numbers)元组
coordinates (10.0, 20.0)
print(coordinates)面向对象编程
类和对象
class Car:def __init__(self, brand, model):self.brand brandself.model modelmy_car Car(Tesla, Model S)
print(my_car.brand)继承
class ElectricCar(Car):def __init__(self, brand, model, battery_size):super().__init__(brand, model)self.battery_size battery_sizemy_electric_car ElectricCar(Tesla, Model S, 100)文件和异常处理
文件操作
with open(file.txt, w) as file:file.write(Hello, world!)with open(file.txt, r) as file:content file.read()print(content)异常处理
try:x int(input(Enter a number: ))y 10 / x
except ValueError:print(Invalid input)
except ZeroDivisionError:print(Cannot divide by zero)模块和包
导入模块
import math
print(math.sqrt(16))创建和使用包
# 在同一目录下创建一个名为my_package的文件夹并在其中创建一个__init__.py文件和一个module.py文件
# module.py中包含以下内容
def hello():print(Hello from module)# 在其他Python文件中导入模块
from my_package.module import hello
hello()网络编程
使用socket
import sockets socket.socket()
host localhost
port 12345s.bind((host, port))
s.listen(5)
conn, addr s.accept()
print(Connected by, addr)数据库操作
使用SQLite
import sqlite3conn sqlite3.connect(example.db)
c conn.cursor()## 创建表
c.execute(CREATE TABLE stocks(date text, trans text, symbol text,qty real, price real))## 插入一条记录
c.execute(INSERT INTO stocks VALUES (2006-01-05,BUY,RHAT,100,35.14))## 查询表
c.execute(SELECT * FROM stocks)
print(c.fetchall())conn.commit()
conn.close()原文https://mp.weixin.qq.com/s/WrjlH84dC9njta-wjIJZ1Q 道阻且长,行则将至,让我们一起加油吧 The End点点关注收藏不迷路