当前位置: 首页 > news >正文

注册营业执照需要什么资料清理优化大师

注册营业执照需要什么资料,清理优化大师,百度搜题,网站开发与设计岗位复习python从入门到实践——函数function 函数是特别难的,大家一定要好好学、好好复习、反复巩固。函数没学好,会为后面造成很大困扰。 教科书中函数举例会稍微有点复杂。在此章复习中,我将整理出容易疏漏和混淆的知识点,并用最简…

复习python从入门到实践——函数function

函数是特别难的,大家一定要好好学、好好复习、反复巩固。函数没学好,会为后面造成很大困扰。
教科书中函数举例会稍微有点复杂。在此章复习中,我将整理出容易疏漏和混淆的知识点,并用最简单的代码辅助大家理解。
本章涉及:定义函数、实参与形参、return返回值、传递列表与切片、将函数导入模块。

文章目录

  • 复习python从入门到实践——函数function
    • 1. 定义 def函数
      • Syntax:
    • 2.实参与形参:
      • 传递实参的方法:
      • 可选实参:
      • 通过*传递任意数量实参
      • 涉及字典 **可变关键字参数
    • 3.return返回
      • Syntax:
      • Principle:
      • 注意:
    • 4. 传递列表
      • [:]切片含义:
    • 5.将函数导入模块

1. 定义 def函数

Syntax:

def 函数():函数的具体表现(函数体)
函数() #调用

区分函数和变量

  1. 函数 add_numbers():
    接受输入的参数(a,b),并且要有返回值return。后面会介绍。
def add_numbers(a, b):# 定义一个函数return a + bresult = add_numbers(3, 5)#使用函数
print("结果:", result)

2.变量x,y
依靠=储存各种数据。

# 定义两个变量
x = 10
y = 20sum_of_variables = x + y # 使用变量
print("变量之和:", sum_of_variables)

2.实参与形参:

形参类似于中文里概括性质的类别,比如“同学”
实参是具体的例子,比如“小明”属于”同学“,”小明“是实参。

def great_user(username):"""显示问候语:""" #文本注释,三引号,描述函数做什么。print(f"Hello {username.title()}!") #函数的工作
great_user('Ashley') 

username 形参
Ashley 实参

传递实参的方法:

(1)对应位置

def animal_lists(category,name):print(f"My {category}'s name is {name.title()}.")
animal_lists('pig','feifei')

(2)关键词,用’='连接

def animal_lists(category,name):print(f"My {category}'s name is {name.title()}.")
animal_lists(name='feifei',category='pig')

(3)最后一项是默认值

def animal_lists(name, category='dog',):#把默认值放到最后。print(f"My {category}'s name is {name.title()}.")
animal_lists(name='feifei')

可选实参:

把可选可不选的参数放到最后一个
middle_name=’ ’

def formatted_name(first_name,last_name,middle_name=' '):if middle_name:formatted_name = f'{first_name} {middle_name} {last_name}'else:formatted_name = f'{first_name} {last_name}'return formatted_name.title()
students = formatted_name('Haifei',"Wang")
print(students)
students = formatted_name('Haifei','Wang','Pig')#最后一个是中间名
print(students)

通过*传递任意数量实参

def feifei_behaviors(*behavior):#通过加星号调用多个实参print(f'飞飞正在:{behavior}')
feifei_behaviors('拉粑粑')
feifei_behaviors('吃粑粑','吃屎','被茵茵看着拉屎')

涉及字典 **可变关键字参数

def build_profile(first,last,**user_info):#**可变关键字参数,除了First和last"""创建一个字典,其中包含我们知道的有关用户的一切"""profile = {}profile['first_name'] = firstprofile['last_name'] = lastfor key,value in user_info.items():profile[key] = valuereturn profile
user_profile = build_profile('albert','einstein',location='princeton',field='physics')
print(user_profile)

3.return返回

Syntax:

def function_name():具体的statementreturn statement中的函数

Principle:

== a. The statements after the return() statement are not executed. 在return()语句之后的语句不会被执行。
b. return() statement can not be used outside the function. return()语句不能在函数外部使用。
c. If the return() statement is without any expression, then the NONE value is returned. 如果return()语句没有任何表达式,则返回NONE值。==

举例:

def formatted_name(first_name,last_name):formatted_name = first_name+' '+ last_namereturn formatted_name()
students = formatted_name('Haifei',"Wang")
print(students)

结果: Haifei Wang

如果没有return语句

def formatted_name(first_name,last_name):formatted_name = first_name+' '+ last_name
students = formatted_name('Haifei',"Wang")
print(students)

结果是None

注意:

调用你定义的函数,而不是变量

def city_country(city, country):full_name = f'{city},{country}'return full_namewhile True:print("Please inter the city and country:")city = input('city:')country = input('country:')new_name = city_country(city, country)#调用定义变量print(new_name)	

4. 传递列表

普通方法:
def+循环+发送列表+调用列表

def greating_lists(names):#建立函数 # 问候 '''给列表中的用户打招呼'''for name in names:print(f'Hello! {name.title()}.')
usernames=['feifei','ashley','tony']# 发送列表
greating_lists(usernames)#调用列表-实参

[:]切片含义:

基本:
[start:stop:step]
用数学集合可以表示为:[ )
举例:
[1:4] 从索引1(包含)到索引4(不包含)也就是索引1 2 3 这几个元素。

重要的容易忽略:
表示列表序列
创建副本

original_list = [10, 20, 30, 40, 50]# 使用切片创建副本
copied_list = original_list[:]# 修改副本
copied_list[0] = 100print("Original List:", original_list)
print("Copied List:", copied_list)

原始列表 original_list 并没有被修改。这是因为切片创建了一个新的列表对象,而不是直接引用原始列表。

5.将函数导入模块

Syntax:
from 文件 import 要导入的东西
import 原来的东西名字 as 你想改的名字
from 文件 import *(所有函数)

http://www.hkea.cn/news/953354/

相关文章:

  • icp备案网站名称更改成都网站设计
  • 企业网站建设需求分析seo排名资源
  • python基础教程雪峰东莞搜索seo网站关键词优化
  • b2b网站开发供应商小程序开发教程全集免费
  • 用自己的手机做网站外链网站是什么
  • 市场调研公司介绍网站推广优化公司
  • 玉溪人民政府网站建设现状新网站seo
  • 湖南餐饮网站建设2023北京封控了
  • 重庆网站设计人员外贸网站搭建推广
  • 局域网内的网站建设西安网站建设公司排名
  • 普通网站报价多少中南建设集团有限公司
  • 蚌埠做网站哪家好全网营销国际系统
  • 沈阳市网站制作谷歌香港google搜索引擎入口
  • 做美食网站的背景高端网站建设制作
  • 文件什么上传到wordpress泉州seo技术
  • 网站地址地图怎么做网页制作的软件有哪些
  • 如何用万网建设网站口碑营销策划方案
  • 做网站的基础架构东莞seo建站公司
  • 嘉兴做网站的哪家好龙岗网站制作
  • 论坛做网站好吗百度官方网页
  • 微信开发者工具获取系统日期seo优化一般包括
  • 怎么用文本做网站百度排行榜风云榜
  • 未来网站开发需求多搜索网站有哪几个
  • 网站建设 成都郑州高端网站制作
  • 快站怎么做淘客网站深圳关键词
  • 做网站时如何去掉网站横条小红书软文案例
  • 图虫南宁百度快速排名优化
  • 上城网站建设app推广文案
  • 网站建设特点宁波seo搜索引擎优化公司
  • 地产商网站建设网球新闻最新消息