Python基础

0. 垃圾

记录一些没见过的、与其他语言不同的新特性

1. 代码块

  • Python依靠缩进数判断代码块(而不是大括号)。
  • 一组连续的、缩进数相同的逻辑行被编译器判断为一个代码块。
  • 在编程时,代码块不能随意创建。
# In python, the indentation means a new code block
print("Hi")
    print("I am Joey") #error
#Cannon start a new code block arbitrarily

 2. 函数

  • 使用def function_name(parameters): 定义函数
  • 接下来使用缩进来创建代码块
def test_function(a,b):
    a=a+10
    b=b+10
    if(a<b):
        print(b, "wins!")
    else:
        print(a, "wins!")

3. 全局变量

  • 在函数中使用全局变量可以给处在该代码块上层的变量赋值

 

global globalV
def test_global():
    global globalV
    globalV = 45
    print("now globalV is", globalV)

 

posted @ 2021-09-10 11:22  JOE_Chin  阅读(66)  评论(0编辑  收藏  举报