跳至主要內容
Shelter for free spirit

Shelter for free spirit

The site is used to record what I have seen and learned in my lifetime, including but not limited to computers, artificial intelligence, mathematics, pop culture, travel, photography, music, aesthetic accumulation etc.

项目名称
项目详细描述
链接名称
链接详细描述
书籍名称
书籍详细描述
文章名称
文章详细描述
伙伴名称
伙伴详细介绍
自定义项目
自定义项目
自定义详细介绍
13. function

1. 函数的定义

计算机中的函数————代码片段

  • 一段具有特定功能的、可重复使用的代码
  • 用函数名来表示并通过函数名来完成功能调用

2. 使用函数的意义

  • 代码的重复利用
  • 减少程序中的代码重复量,使代码更加容易被理解;
  • 让代码更易于维护与更新

3. 函数的使用

  1. 内置函数:
  • Python 编程语言中已经被定好功能的函数
  • 可以直接调用来执行特定的任务

Ryan原创...大约 6 分钟pythonpython编程教程
12. for

1. for 循环遍历列表每个元素

students_list = ['lilei', 'hanmeimei', 'madongmei']
for student in students_list:
    print(student)

# output
lilei
hanmeimei
madongmei

Ryan原创...大约 6 分钟pythonpython编程教程
11. while

1. while 循环

while not user_answer_correct:
    user_gender = input('请输入您的性别(F/M):')
    if user_gender == 'F':
        print('您是女生')
        user_answer_correct = True
    elif user_gender == 'M':
        print('你是男生')
        user_answer_correct = True
    else:
        print('wrong')

Ryan原创...大约 6 分钟pythonpython编程教程
10. if

1. 前提:注意缩进

  • 在 python 中相同位置的代码表示他们是同一个代码块

  • 用四个空格或者一个 Tab 来表示缩进(切忌混用!)

condition = True
while condition:
    a = 1
    if a < 10:
        print(f'a>>>{a}')

Ryan原创...大约 2 分钟pythonpython编程教程
9. bool

1. 布尔值

意义:表示判断中的是与否。一般用于条件测试中。

In [1]: a = True

In [2]: a
Out[2]: True

In [3]: 10 < 5
Out[3]: False

In [4]: 10 > 8
Out[4]: True

Ryan原创...大约 3 分钟pythonpython编程教程
8. set

1. 创建集合

  1. 直接使用花括号创建集合
set1 = {1, 2, 4, 5, 8}

Ryan原创...大约 2 分钟pythonpython编程教程
7. Dictionary

1. 如何构建一个电话薄

我们有以下联系人:

姓名 手机号
李雷 123456
韩梅梅 132456
大卫 154389
Mr.Liu 131452
Bornforthis 180595
Alexa 131559

Ryan原创...大约 8 分钟pythonpython编程教程
basic knowledge extension for Python

引言: 这篇文章旨在为 Ryan 本人服务

1. 基本语法元素

1.1 格式化输出

  1. 填充输出
# 右对齐
a = 123
print('{0:_>4}'.format(a)) # _123
b = 1111
print('{0:&>10}'.format(b)) # &&&&&&1111
# 左对齐
a = 'a'
print('{0:*<5}'.format(a)) # a****
# 居中
a = 'middle'
print('{0:#^16}'.format(a)) # #####middle#####
print('{0:#^15}'.format(a)) # ####middle#####
print('{0:#^17}'.format(a)) # #####middle######

Ryan原创...大约 31 分钟pythonpython编程教程
some function in ai maths

1. 高等数学

  • sympy
# 导入sympy 中所有内容
from sympy import *

Ryan原创...大约 2 分钟AI Mathematicspython编程教程