1. 程式人生 > >Day1[下] - Python基礎 基本語法、流程控制

Day1[下] - Python基礎 基本語法、流程控制

數字 tin 流程 label reference rst too ren ogr

一、變量\字符編碼

Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.

變量定義的規則:

      • 變量名只能是 字母、數字或下劃線的任意組合
      • 變量名的第一個字符不能是數字
      • 以下關鍵字不能聲明為變量名
        [‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘exec‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘lambda‘, ‘not‘, ‘or‘, ‘pass‘, ‘print‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘, ‘with‘, ‘yield‘]

變量的賦值:

name = ‘Tao Three‘
name2 = name

print(‘before:‘,name,name2)

name2 = ‘xiao Tao‘

print(‘after:‘,name,name2)

  

Day1[下] - Python基礎 基本語法、流程控制