備忘錄_20160105(定位) 修改 回首頁

程式 2021-09-18 00:00:19 1631894419 100
念書 python 3

念書 python 3

print("水果",end="\n");
print("恐龍",end="");
print("對嗎");
print(12345);
print("abs"+str(-3));
print(18+float("-3.5"));
print(18+int("-3"));

"""
# 基本結構

import 模組

全域變數

def 函數名稱1(參數列):
    程式敘述1~m

...

def 函數名稱n(參數列):
    程式敘述1~p

程式敘述1~q
"""

import math;
print(math.cos(1.43));

sum = 1 + 2 + \
      3 + 4 + \
      5;
print(sum);

colors = ['red',
          'blue',
          'yellow'];
print(colors);


iAge=None;
iAge=43;
print(iAge);

iAddressOfIAge=id(iAge);
print("address if iAge is "+str(iAddressOfIAge));


score1 = score2 = score3 = 25;
print(score1, score2, score3);

x, y = 1, 2;
print(x,y);
x,y=y,x; # x與y互換
print(x,y);

# 2021-09-17 讀到 3-20 頁

------------------------------------

●取得資料型態

type(a); # <class 'int'> 或 <class 'float'> 或 <class 'str'> 或 <class 'bool'> 或 <class 'complex'>

str(type(a)); # "<class 'int'>" 或 "<class 'float'>" 或 "<class 'str'>" 或 "<class 'bool'>" 或 "<class 'complex'>"

●資料型態轉換函數

str()
int()
float()

●資料型態
(a).數值 Number
(b).字串 String
(c).布林 Boolean
(d).[容器型態 Contains Type] 清單/列表/串列 List
(e).[容器型態 Contains Type] 元組 Tuple
(f).[容器型態 Contains Type] 集合 Set
(g).[容器型態 Contains Type] 字典 Dictionary

(a-1).整數資料型態

 a10=29; (十進位)
 a02=0b1101011; (二進位)
 a08=0o15; (八進位)
 a16=0xFB; (十六進位)

(a-2).浮點數資料型態

 a2=88.2;

(a-3).複數資料型態

 a3=4+5j;

# 2021-09-19 讀到 3-21 頁

(b).字串資料型態

 str1="用雙引號";

 str2='用單引號';

 str3="""這樣也行""";

 str4='''就是要
換行啦~''';

(c).布林資料型態

 x=True;

 y=False; # 0, 0.0, [], (), {}, None 都視為 False

# 2021-09-20 讀到 3-27 頁