python学习之路☞7.Primitive Data Types, Data Structure, Branch Conditional, Funcation

python学习之路☞7.Primitive Data Types, Data Structure, Branch / Conditional, Funcation

#python,#data type,#data structure,#branch/conditional structure,#funcation,

数据类型(Data Type)

  1. 对数据的一种分类,规定了数据可以取什么值、可以进行哪些操作,以及在计算机中如何存储。
  2. 基本数据类型(Primitive Data Types):
    • 整数(int)
    • 小数/浮点数/浮点数(float)
    • 复数(实部 + 虚部)(complex)
    • 布尔(boolean)
    • 字符串(string)
  3. 一个变量存一个值

数据结构(Data Structure)

  1. 数据在计算机中的组织和存储方式。
  2. 它解决的是:
    • 数据怎么存、怎么组织、怎么方便使用。
  3. 内置数据结构主要有 4 种核心类型:
    • 列表(list)
    • 元组(tuple)
    • 字典(dict)
    • 集合(set)
  4. 一个变量存多个值

另一种数据分类

python内置类型(Python Built-in Types)
  - 数值(Numeric)
    - int
    - float
    - complex

  - 序列(Sequence)
    - str  # 之前学到的字符串也是一种 **序列型数据结构**。
    - list
    - tuple
    - range

  - 映射(Mapping)
    - dict

  - 集合(Set)
    - set

  - 布尔(Boolean)
    - bool

分支结构(Branch / Conditional Structure)

  1. 程序在执行过程中,根据条件的不同选择不同的执行路径
  2. 控制程序流程的一种结构。属于 程序控制结构

函数(Funcation)

  1. 一个具有名称的代码块,把一段完成特定任务的代码封装起来,需要时可以通过函数名反复调用。
  2. 使用 def 来定义函数,并使用函数名调用。
    '''
    # 定义函数
    def 函数名():  
        函数体
    
    # 调用
    函数名()
    '''
    
  3. 示例
    def say_hello():
        print("Hello")
    
    say_hello()
    

0

语句(statement)

  1. 一行代码块,最小可执行单位——它执行一个动作,但本身没有返回值

参考

data-types
data-structures
functions
statement

Comments