Python基本用法

172 阅读1分钟

Python --笔记

www.runoob.com/python3/pyt…

1、python安装

  • www.python.org/
  • 自己的百度网盘--python-3.8.2-amd64
  • 本机使用的python3.8.2

2、python基础

编码

  • utf-8

标识符

  • 第一个字符必须是字母表中字母或下划线 _
  • 标识符的其他的部分由字母、数字和下划线组成
  • 标识符对大小写敏感

关键字

  • 我们不能把它们用作任何标识符名称。
#Python 的标准库提供了一个 keyword 模块,可以输出当前版本的所有关键字  
>>> import keyword
>>> keyword.kwlist

['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

注释

  • 单行#
  • 多行 '''"""
"""
坡度、坡向、山体阴影
@source:原始数据源
@ProcessType:具体处理方案,坡度/坡向/山体阴影
@outTif:输出文件位置及文件名
@format:数据类型
"""
def CreateSpeDemPro(source,ProcessType,outTif,format):
    dataSource = gdal.Open(source)#打开数据源
    if(ProcessType == 'slope'):
        gdal.DEMProcessing(outTif,dataSource,'slope',format = format)#坡度
    elif(ProcessType == 'aspect'):
        gdal.DEMProcessing(outTif, dataSource, 'aspect', format=format)#坡向
    else:
        gdal.DEMProcessing(outTif, dataSource, 'hillshade', format=format)#山体阴影

多行语句

Python 通常是一行写完一条语句,但如果语句很长,我们可以使用反斜杠 ** 来实现多行语句,例如:

total = item_one + \
        item_two + \
        item_three

在 [], {}, 或 () 中的多行语句,不需要使用反斜杠 ****,例如:

total = ['item_one', 'item_two', 'item_three',
        'item_four', 'item_five']

等待用户输入

执行下面的程序在按回车键后就会等待用户输入:

#!/usr/bin/python3  input("\n\n按下 enter 键后退出。")

以上代码中 ,**\n\n** 在结果输出前会输出两个新的空行。一旦用户按下 **enter** 键时,程序将退出。

3、python使用

  • python3使用方式如下--菜鸟教程python3

www.runoob.com/python3/pyt…