跳至主要內容
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.

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

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

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

# output
lilei
hanmeimei
madongmei

Ryan原创...大约 1 分钟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原创...大约 3 分钟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编程教程
6. Tuple

1. 创建元组

  • 使用小括号创建;
  • 里面元素用英文逗号隔开;
tup = ('a', 'b', 'c')
print(tup, type(tup))

# output
('a', 'b', 'c') <class 'tuple'>

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