1. 函数的定义
计算机中的函数————代码片段
- 一段具有特定功能的、可重复使用的代码
- 用函数名来表示并通过函数名来完成功能调用
2. 使用函数的意义
- 代码的重复利用
- 减少程序中的代码重复量,使代码更加容易被理解;
- 让代码更易于维护与更新
3. 函数的使用
- 内置函数:
- Python 编程语言中已经被定好功能的函数
- 可以直接调用来执行特定的任务
原创...大约 6 分钟
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.
计算机中的函数————代码片段
students_list = ['lilei', 'hanmeimei', 'madongmei']
for student in students_list:
print(student)
# output
lilei
hanmeimei
madongmei
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')
在 python 中相同位置的代码表示他们是同一个代码块
用四个空格或者一个 Tab 来表示缩进(切忌混用!)
condition = True
while condition:
a = 1
if a < 10:
print(f'a>>>{a}')
意义:表示判断中的是与否。一般用于条件测试中。
In [1]: a = True
In [2]: a
Out[2]: True
In [3]: 10 < 5
Out[3]: False
In [4]: 10 > 8
Out[4]: True
我们有以下联系人:
姓名 | 手机号 |
---|---|
李雷 | 123456 |
韩梅梅 | 132456 |
大卫 | 154389 |
Mr.Liu | 131452 |
Bornforthis | 180595 |
Alexa | 131559 |
引言: 这篇文章旨在为 Ryan 本人服务
# 右对齐
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######
# 导入sympy 中所有内容
from sympy import *