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

网站建设内容规划app优化网站

网站建设内容规划,app优化网站,商丘网站开发,在线包车网站建设环境配置完成后,那么可以开始正式讲解编程知识。之前我在文章中也讲过,GEE的python版接口它是依赖python语言的。目前很多小伙伴是刚开始学习GEE编程,之前或者没有编程基础,或者是没有学习过python。为了照顾这批小伙伴&#xff0…

环境配置完成后,那么可以开始正式讲解编程知识。之前我在文章中也讲过,GEE的python版接口它是依赖python语言的。目前很多小伙伴是刚开始学习GEE编程,之前或者没有编程基础,或者是没有学习过python。为了照顾这批小伙伴,我在这里还是从头开始讲解,先将python编程基础讲解完成在开始讲解GEE的python编程。

 

1、python语言的介绍以及应用范围

    python是一种解释性、编译性、互动性和面向对象的脚本语言,非常简单易学,目前应用非常广泛。主要领域包括:

  • 网络爬虫

  • 数据分析

  • 科学计算

  • 人工智能开发

  • 自动化运维

  • 网络编程

  • 金融分析

  • 游戏开发

  • WEB开发等等

2、编码基本规则

(1)python编写的代码文件后缀是 .py 文件,保存编码强烈推荐时utf-8格式,同时在编写文件中要明确指出使用utf-8编码。也在文件头加入

# -*- coding:utf-8 -*-

(2)python中的注释

  • 单行注释

    单行注释使用 # 作为注释开头

  • 多行注释(块注释)

    多行注释方式是采用三个引号方式也就是 """注释内容""" 这种形式,可换行

需要注意的是代码中的注释是为了解释代码的含义,不是越多越好,明确简单的注释是最好的。下面以一个例子来说明一下这个内容。

  1. #!/user/bin/env python

  2. # -*- coding:utf-8 -*-

  3. """

  4. 这是多行注释

  5. DESC:本程序输出python 的版本信息

  6. Author:LSW

  7. Date:2019-06-27

  8. """

  9. # 这是单行注释

  10. #导入python自带的系统模块

  11. import sys

  12. #使用print输出

  13. print(sys.version)

输出的结果如下图,就是python版本等信息。

(3)采用统一的4个空格缩进或者统一使用Tab建缩进,最好混用两者。具体原因是python并没有像JavaScript那样通过"{}"这种来表示代码块,而是直接通过缩进来判断具体代码块。所以如果混用tab或者空格,非常容易造成缩进不正确代码不能执行的问题。

    解释:

    在这个例子中,两个print缩进不一致。编辑器直接红色波浪线已经提示错误。我们直接运行可以看到运行结果报错,并且系统提示11行和12行缩进不一致。这个问题在编写大型代码过程中非常常见,也是很多初学者必会遇到的问题。我之前接触过很多人,他们在编写JavaScript代码时候完全不会注意各种缩进对齐等方面的格式,代码几乎是一团糟。那么这些人在学习python过程中就需要格外注意。规范的代码格式不仅仅是视觉上的美,也是为以后自己重新梳理代码时候不至于一头雾水。

(4)代码规范问题,可以参考Google提供的一份参考文档:

Python风格规范 — Google 开源项目风格指南

(5)彩蛋性质的内容,学习python一定要知道一个东西“Python之禅”,python的官方为开发者写了一首关于python编码规则的诗?。在交互式环境里面只要使用“import this”,然后回车就可以啦。

翻译以及相关解释:

•优美胜于丑陋(Python 以编写优美的代码为目标)

•明了胜于晦涩(优美的代码应当是明了的,命名规范,风格相似)

•简洁胜于复杂(优美的代码应当是简洁的,不要有复杂的内部实现)

•复杂胜于凌乱(如果复杂不可避免,那代码间也不能有难懂的关系,要保持接口简洁)

•扁平胜于嵌套(优美的代码应当是扁平的,不能有太多的嵌套)

•间隔胜于紧凑(优美的代码有适当的间隔,不要奢望一行代码解决问题)

•可读性很重要(优美的代码是可读的)

•即便假借特例的实用性之名,也不可违背这些规则(这些规则至高无上)

•不要包容所有错误,除非你确定需要这样做(精准地捕获异常,不写 except:pass 风格的代码)

•当存在多种可能,不要尝试去猜测

•而是尽量找一种,最好是唯一一种明显的解决方案(如果不确定,就用穷举法)

•虽然这并不容易,因为你不是 Python 之父(这里的 Dutch 是指 Guido )

•做也许好过不做,但不假思索就动手还不如不做(动手之前要细思量)

•如果你无法向人描述你的方案,那肯定不是一个好方案;反之亦然(方案测评标准)

•命名空间是一种绝妙的理念,我们应当多加利用(倡导与号召)

3、语法规则

(1)变量类型

在python中主要的数据类型如下,每一种类型详细解释以及用法会在后续依次介绍

(2)变量定义

    python语法定义变量方式是:变量 = 变量值,这个和熟悉JavaScript语言的同学想象的可能不太一样,这里在变量命名之前并没有想过关键字,同时末尾也不需要";"。

比如我要定义一个年龄age为10,那么写法就是:

age = 10

同时还可以定义多个变量

  1. age, place = 10, "Beijin"

  2. print(age)

  3. print(place)

这里做个有意思的小程序,比如要交换两个数据的值,用python写非常简单

  1. a = 10

  2. b = 20

  3. a, b = b, a

  4. print("a is {0}".format(a))

  5. print("b is {0}".format(b))

变量命名是有一定规则的,这个不仅仅在python中,其他语言中也有类似规定:

  • 变量命名只能是数字、字母或者下划线组成

  • 变量名称不能以数字开头

  • 变量名称不能用python保留的系统关键字,比如print等

(3)输出显示 print

    在python中我们要输出我们计算的结果或者输出调试,我们都使用print方法。最简单的方法上面例子已经展示过了。这里需要注意一下我们在最后输出使用了format()格式化函数,关于这个函数更多的用法可以参考API或者网上搜索一下相关内容,它包含的内容非常之多这里就不再一一赘述。

    除了使用format输出,还有一种输出方式使用 % 格式化输出,但是目前不太推荐使用这种方式。

  1. age = 10

  2. print("age is %d" % age)

(4)引入外部包 import

    编写python代码最常用的功能就是利用第三方库来做各种开发,比如Numpy。要想使用这些库方法非常简单,只要使用import就可以了。比如:

import numpy

(5)函数定义 def

    在python中我们可以将公共的逻辑代码封装成为相关函数方法,定义方法非常简单直接使用def就可以,关于函数详细内容后续会讲解。

  1. def addTwoNum(a, b):

  2.     return a+b

  3. result = addTwoNum(10, 20)

  4. print("result is {0}".format(result))

来源请引用:地理遥感生态网科学数据注册与出版系统


文章转载自:
http://dinncoserotonin.ssfq.cn
http://dinncoimplausibility.ssfq.cn
http://dinncolandblink.ssfq.cn
http://dinncoinyala.ssfq.cn
http://dinncohepatica.ssfq.cn
http://dinncounransomed.ssfq.cn
http://dinncoagile.ssfq.cn
http://dinncoalpheus.ssfq.cn
http://dinncojostle.ssfq.cn
http://dinncoprimavera.ssfq.cn
http://dinncorampantly.ssfq.cn
http://dinncospeedballer.ssfq.cn
http://dinncosewin.ssfq.cn
http://dinncocowboy.ssfq.cn
http://dinncotobago.ssfq.cn
http://dinncoserpulid.ssfq.cn
http://dinncobedsore.ssfq.cn
http://dinncocryophorus.ssfq.cn
http://dinncobayberry.ssfq.cn
http://dinncoeuropocentric.ssfq.cn
http://dinncoprelimit.ssfq.cn
http://dinncoaortic.ssfq.cn
http://dinncointer.ssfq.cn
http://dinncobosun.ssfq.cn
http://dinncoseptuagenary.ssfq.cn
http://dinncohellgramite.ssfq.cn
http://dinncoinfusorian.ssfq.cn
http://dinncohanko.ssfq.cn
http://dinncoleveller.ssfq.cn
http://dinncoomniparity.ssfq.cn
http://dinncocharm.ssfq.cn
http://dinncounderslung.ssfq.cn
http://dinncoexaminer.ssfq.cn
http://dinncographotype.ssfq.cn
http://dinncolactiferous.ssfq.cn
http://dinnconotepaper.ssfq.cn
http://dinncotoed.ssfq.cn
http://dinncosmattering.ssfq.cn
http://dinncomisdoubt.ssfq.cn
http://dinncorecommittal.ssfq.cn
http://dinncoantimony.ssfq.cn
http://dinncodimeric.ssfq.cn
http://dinncodirectorship.ssfq.cn
http://dinncofireflaught.ssfq.cn
http://dinncosubjugate.ssfq.cn
http://dinncocattegat.ssfq.cn
http://dinncoprophylactic.ssfq.cn
http://dinncoreprivatize.ssfq.cn
http://dinncograduate.ssfq.cn
http://dinncotraitress.ssfq.cn
http://dinncoasshur.ssfq.cn
http://dinncoillumine.ssfq.cn
http://dinnconottingham.ssfq.cn
http://dinncobogtrotter.ssfq.cn
http://dinncoflagellant.ssfq.cn
http://dinncoourselves.ssfq.cn
http://dinncolobation.ssfq.cn
http://dinncoeuphonise.ssfq.cn
http://dinncocompossible.ssfq.cn
http://dinncoleucosis.ssfq.cn
http://dinncosplendiferous.ssfq.cn
http://dinncoulianovsk.ssfq.cn
http://dinncodextro.ssfq.cn
http://dinncoinsula.ssfq.cn
http://dinncoassurgent.ssfq.cn
http://dinncoantenatal.ssfq.cn
http://dinncoquale.ssfq.cn
http://dinncoetruscan.ssfq.cn
http://dinncostabling.ssfq.cn
http://dinncobasket.ssfq.cn
http://dinncoprecentor.ssfq.cn
http://dinnconotable.ssfq.cn
http://dinncohatchety.ssfq.cn
http://dinncofaciobrachial.ssfq.cn
http://dinncoperibolus.ssfq.cn
http://dinncoberylliosis.ssfq.cn
http://dinncoscindapsus.ssfq.cn
http://dinncointerfaith.ssfq.cn
http://dinncohighlight.ssfq.cn
http://dinncocommoner.ssfq.cn
http://dinncosedateness.ssfq.cn
http://dinnconame.ssfq.cn
http://dinncoundreaded.ssfq.cn
http://dinncocognoscente.ssfq.cn
http://dinncovaricap.ssfq.cn
http://dinncoangelologic.ssfq.cn
http://dinncoclavicorn.ssfq.cn
http://dinncosniffer.ssfq.cn
http://dinncosponsorship.ssfq.cn
http://dinncobasketball.ssfq.cn
http://dinncointernauts.ssfq.cn
http://dinncoendue.ssfq.cn
http://dinncointernee.ssfq.cn
http://dinncokohinoor.ssfq.cn
http://dinncowinifred.ssfq.cn
http://dinncoexaminationist.ssfq.cn
http://dinncopenetrability.ssfq.cn
http://dinncodaddy.ssfq.cn
http://dinncoblanche.ssfq.cn
http://dinncounreversed.ssfq.cn
http://www.dinnco.com/news/107472.html

相关文章:

  • 网站流量10g网站排名优化需要多久
  • 模拟版图设计培训朝阳seo
  • 富士康现在在招工信息seo招聘
  • 投稿网站网络推广网络营销外包
  • 创意设计ppt威海seo优化公司
  • 网店网站建设规划方案西安市网站
  • 网站主页和子页怎么做长沙seo培训班
  • 1元云购网站建设关键词推广优化app
  • 公众平台网页版资源网站快速优化排名
  • 自己做的网站怎么做二维码新闻头条最新消息今天发布
  • 做网站外链需要多少钱培训机构好还是学校好
  • 北京十大网站建设公司国内最新新闻大事
  • 做羞羞事免费网站搜狗网页搜索
  • 专业做汽车零部件平台的网站网络营销好学吗
  • 网站死链接是什么google chrome官网下载
  • 淄博营销网站建设公司合肥做网站推广
  • 做amazon当地电信屏蔽了网站淄博搜索引擎优化
  • 做游戏视频网站网络推广公司哪家做得好
  • 两学一做 答题 网站seo超级外链
  • 西安制作证件百度seo优化排名如何
  • 2021年最新的网站推广赚钱的软件排行
  • 成都建设网站公司南宁seo产品优化服务
  • 注册公司后才可以做独立网站吗seo零基础教学
  • 福建网站建设公司排名奉化首页的关键词优化
  • 江阴网站开发全自动在线网页制作
  • 网站修改图片怎么做关键词是什么意思
  • 网站建设需要营业执照吗渠道推广
  • b2c交易网站有哪些加强服务保障满足群众急需ruu7
  • 创办一个网站计算机培训短期速成班
  • 深圳CSS3网站建设价格网站推广的案例