一、Python基本知識

1.Python屬高階語言,所編築的是字節碼

2.一般狀態statement 終止於換行,如需使用多數行編寫,可在行末加上 \,以表延續

但在 parentheses ( ), brackets [ ] and braces { }中,換行則沒有影響

3.其他語言使用{}來圈分code,但Python 則使用 indentation(縮排) 來圈分

4.Python 使用  hash (#) symbol to start writing a comment,multiple lines 則用 """  """

5.可以在同一個Statment中assigning multiple values to multiple variables

a, b, c = 5, 3.2, "Hello"

6.變量

只能由字母、數字、下划線構成,但不能以數字開頭,亦不能與功能關鍵字相同

(ex: and, or, as, assert, break, class, continue, def, del, elif, else, if ,expect, exec, finally, for ,in, while, from, global, import, input, print, is, not ,pass, return, try, with, yeild)

二、literals共有8種  

(Numeric(1234)   String('1234')  Boolean(True/False)  List['1','2','3' ]  Tuple(1,2,3)    Dict{key+valuse}   Set{object}   Special(none))

三、Datatype共有6種

1.Numbers

They are defined as intfloat and complex class in Python

2.List

List is an ordered sequence of items. All the items in a list do not need to be of the same type.

3.Tuple

Tuple is an ordered sequence of items same as list.The only difference is that tuples are immutable. Tuples once created cannot be modified

4.Strings

String is sequence of Unicode characters

5.Set

Set is an unordered collection of unique items. Set is defined by values separated by comma inside braces { }.

6.Dictionary

Dictionary is an unordered collection of key-value pairs.

To convert to dictionary, each element must be a pair

>>> dict([[1,2],[3,4]])
{1: 2, 3: 4}
>>> dict([(3,26),(4,44)])
{3: 26, 4: 44}

四、輸入輸出

1.使用print()輸出,內部可加上("文字", function),其中逗號會自動轉為space

a = 5

print('The value of a is', a)
# Output: The value of a is 5

亦可加上 sep  end

print(1,2,3,4)
# Output: 1 2 3 4 print(1,2,3,4,sep='*')
# Output: 1*2*3*4 print(1,2,3,4,sep='#',end='&')
# Output: 1#2#3#4&

可使用str.format()的取代功能(見後續format章節)

2.使用input()輸入

3.使用 import keyword 帶入整組module,亦可用 from keywords 再import 帶入想要的功能

import math
print(math.pi)

>>>from math import pi
>>>pi
3.141592653589793

五、Operators

1.Arithmetic operators 計算符

7 + 3 = 10

7 - 3 = 5

7 * 3 = 21

7 / 3 = 2.33333333

7 // 3 = 2 (商)

7 % 3 = 1 (餘)

7 ** 3 = 343 (方)

2.Comparision operators  關係符

< (小於)   <= (小於等於)   == (等於)  >= (大於等於)  > (大於)  != or <> (不等於)

K = 1 (令K為1)   K == 1 (K與1相同 / 比較用)

3.Logical operators  邏輯符

4.Bitwise operators (還不重要)

5.Special operators

5.1.Identity operators ( is / is not)

*[ ] ( ) { }  are not identical,結果為False

5.2.Menbership operators ( in / not in)

*{ } 中只能檢測 key,無法檢測value

六、命名

可將Object命名,其中 Function也算object

命名有階層獨立性,範圍上Built-in > Global > Local Namespace,故重複命名時Local可視為在Global裡再切一塊,當返回Global時及恢復成Global的值

a = 10
def outer_function():
a = 20 def inner_function():
a = 30
print('a =', a)
inner_function()
print('a =', a) outer_function()
print('a =', a)
#a = 30
#a = 20
#a = 10

七、條件語句

If  elif  elif  else

判定結果為 True/False (bool值)

支援 [Pass  in  not in]

有關係符 ( < (小於)   <= (小於等於)   == (等於)  >= (大於等於)  > (大於)  != or <> (不等於) )

name = "ABC"  其字符串的子序列 "A" "B" "C" "AB" "BC" "ABC" 都可被 in 判定為 True,但字符串內部為有序,故"AC"則為False

八、迭代循環

1.While 循環 (無限循環,可加上終止條件語句)

支援 [ 條件If  Pass  continue(跳回上層循環)  break(直接終止循環) ]

2.For ____ in ____ 循環

https://www.programiz.com/python-programming/if-elif-else

Python开发 基礎知識 (未完代補)的更多相关文章

  1. Python开发 基礎知識 3.類別&方法 (bool & str) (未完待續)

    類別 可使用type()查看 內建 [ 布爾:bool (Boolen) 字串:str (String) 數字:int (Integer) 小數:float 列表:list 元祖:tuple 字典:d ...

  2. Python开发 基礎知識 2.變量 ( *arg, **kwargs )

    變量 *args 和 **kwargs ( *和**為本體,名稱為通俗的名稱約定 ) *args 用於函式定義. 可將不定數量的參數傳遞給一個函數,傳入函式的引數,會先以Tuple物件收集,再設定給參 ...

  3. JavaScript基礎知識

    JavaScript基礎知識 1.標籤組使用 <script charset='utf-8' //設置字元集 defet //使腳本延遲到文檔解析完成,Browser已忽略 language=' ...

  4. BootStrap基礎知識

    BootStrap基礎知識 1. .lead //突出 .text-left //文字居左 .text-right //文字居右 .text-center //文字居中 .text-justify / ...

  5. CSS1-3基礎知識

    CSS1-3基礎知識 1.css排版 css在html內排版: <style type='text/css'> 標記名{} .類型名{} #ID名{} 標記名,.類型名,#ID名{} &l ...

  6. jQuery基礎知識

    jQuery基礎知識 $(function(){}) //jQuery先執行一遍再執行其他函數 $(document).ready(fn) //文檔加載完後觸發 1. 刪除$:jQuery.noCon ...

  7. Python开发 標準內建方法 (未完代補)

    abs(number)  絕對值  The abs() method takes a single argument: num - number whose absolute value is to ...

  8. HTML 4.01+5基礎知識

    HTML 4.01+5 1.Html結構:html>head+body 2.Html快捷鍵:!加Tab(在sublime中) 3.雙標籤: ①常用標籤 h1.h2.h3.h4.h5.h6 p.c ...

  9. Linux基礎知識 —— open&close

    下面說一下在用戶空間調用open/close/dup跟驅動中的open和release的對應. 下面是測試驅動: #include <linux/module.h> #include &l ...

随机推荐

  1. HDU4745--区间DP+回文串

    这题的题意为,给你一个环状的字符串,有两只兔子分别从某任意的石头上开始跳跃.一只顺时针跳.一只逆时针跳.两只兔子每一次落脚处石头的质量都相同.兔子要一步一步的跳,且不能跳到之前跳到过的地方.总的来说, ...

  2. POJ1141 Brackets Sequence---区间DP+输出路径

    题目意思就是输入一串括号,让你找到最小的补偿数目使括号串合法,并且输出补全后的串. 基本是区间DP的模板题,该题特别让你输出补全后的答案.这和区间dp的反向思路很像,就是把一个大的区间划分为多个互不干 ...

  3. .NET Core 配置GC工作模式与内存的影响

    .NET Core 配置GC工作模式与内存的影响 .NET Core GC 原文:https://blog.markvincze.com/troubleshooting-high-memory-usa ...

  4. Linux文件结构

    /: 根目录,所有的目录.文件.设备都在/之下,/就是Linux文件系统的组织者,也是最上级的领导者. /bin: bin 就是二进制(binary)英文缩写.在一般的系统当中,都可以在这个目录下找到 ...

  5. java基础 (三)之ConcurrentHashMap(转)

    一.背景: 线程不安全的HashMap     因为多线程环境下,使用Hashmap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用HashMap.   效率低下的H ...

  6. Java 设置PDF文档背景——单色背景、图片背景

    一般生成的PDF文档默认的文档底色为白色,我们可以通过一定方法来更改文档的背景色,以达到文档美化的作用. 以下内容提供了Java编程来设置PDF背景色的方法.包括2种设置方法: 设置纯色背景色 设置图 ...

  7. Anaconda 创建环境

    2019-03-25 17:10:51 Anaconda 给不同的项目创建不同的环境真的非常重要,最近在使用flask的时候在base环境中安装flask-bootstrap,竟然将我原本的py3.7 ...

  8. idea启动springboot项目 报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader;

    有一次启动springboot项目的时候,报了一个非常奇怪的错误,说是找不到servletContext,springboot不是自带tomcat的吗? 在网上找了好久,说是用以下方式解决. 解决方式 ...

  9. openLDAP安装时无法操作根节点数据,提示的是This base cannot be created with PLA.

    1.无法操作根节点数据,提示的是This base cannot be created with PLA. 解决办法 1)添加一个base.ldif文件,里面的dc和配置文件里的保持一致即可 dn: ...

  10. linux grep find查找文件夹、代码中的某行/字符串

    本文转载于:https://blog.csdn.net/Mr_Cat123/article/details/80541658 在Linux中,由于文件很多,代码很长,可能我们只知道其中的一两个字符串, ...