python讀書筆記 一

2021-07-30 06:19:24 字數 1802 閱讀 9228

一,python語法8要素
#!/usr/bin/env python3

print("hello world")

#資料型別

int("45")

str(912)

#使用"hard times"[5]

#物件引用

x = "bule"

y = "green"

z = x

#元組使用逗號建立

tuple = ("denmark", "finland", "norway","sweden")

#in, not in 成員操作符

p = (4, "frog", 9, -33, 9, 2)

2 in p

"dog" not in p

#邏輯運算子 and or not,返回決定結果的運算元,不返回bool值

five = 5

two = 2

zero = 0

five and two

two and five

five and zero

#if語句

lines = 500

if lines < 1000:

print("small")

elif lines < 10000:

print("medium")

else :

print("large")

#while語句

while true:

item = get_next_item()

if not item:

break

process_item(item)

#for in語句

countries = ["denmark", "finland", "norway","sweden"]

for countrie in countries:

print(countrie)

#算數操作符+,-,*,/

5 + 6

#輸出print

print("type interges, each followed by enter; or just enter tofinish")

total = 0

count = 0

while true:

line = input("integer:")

if line:

try:

number = int (line)

except valueerror as error:

print(error)

continue

total += number

count += 1

else:

break

if count:

print("count = ", count,"total = ", total, "mean = ", total / count)

#函式建立及呼叫

def get_int(msg):

while true:

try:

i = int(input(msg))

return i

except valueerror as err:

print(err)

age = get_int("enter your age:")

#匯入模組improt

import random

x = random.randint(1, 6)

python讀書筆記

numpy篇 numpy.around 函式返回指定數字的四捨五入值 numpy.floor numpy.floor 返回小於或者等於指定表示式的最大整數,即向下取整 numpy.ceil numpy.ceil 返回大於或者等於指定表示式的最小整數,即向上取整 numpy.reciprocal nu...

python讀書筆記

python有六個標準的資料型別 1.number 數字 int,float,bool,complex 2.string 字串 3.tuple 元祖 4.list 列表 5.dictionary 字典 6.sets 集合 迭代器 迭代器物件從集合的第乙個元素開始訪問,直到所有的元素被訪問完結束。迭代...

Python讀書筆記

第一章 python基礎 tuple又叫元組 一旦初始化就不可再改變 dict又叫字典,d 2 set和dict類似,也是一組key的集合,但不儲存value。由於key不能重複,所以,在set中,沒有重複的key。s set 1,1,2,2,3,3 set可以看成數學意義上的無序和無重複元素的集合...