# -*- coding: utf-8 -*-
"""created on fri oct 12 15:40:37 2018
@author: administrator
"""#%%
import tensorflow as tf
import numpy as np
a = np.array([1,2,3,4,5,6,7,8,9],dtype='float32');
a = a.reshape(3,3);
c = a + [22,33,44];#c.dtype='float64'
c = c.astype(np.float32)
#c.dtype = 'float32'
print('c=',c);
condition = 1
while (condition < 10):
print(condition)
condition = condition + 1
example_list = [1,2,3,4,5,6,7,88,99]
for i in example_list:
print(i)
for i in range(len(example_list)):
print(i)
print(example_list[i])
for i in range(2,10):
print(i)
x = 1
y = 0
z = 3
if(x>y):
print('x>y')
elif(x==y):
print('x=y')
else:
print('xdef func(x,y=3):
a = x;
b = y;
c = a + b;
print(c)
return a,b,c
d1,d2,d3=func(3,4)
#%%variable
def func(x,y=3):
a = x;
b = y;
print(a)
func(3)
func(3)
#%%檔案寫
text = 'this is my first test.\nthis is my second test.\nthis is my end test.\n'
filename = r'c:\users\administrator\desktop\python\my file.txt'
my_file = open(filename,'w')
my_file.write(text)
my_file.close()
text = 'this is my first test.\nthis is my second test.\nthis is my end test.\n'
filename = r'c:\users\administrator\desktop\python\my file.txt'
my_file = open(filename,'a')
my_file.close()
#%%檔案讀
filename = r'c:\users\administrator\desktop\python\my file.txt'
my_file = open(filename,'r')
read_text = my_file.read()
#read_text1 = my_file.readlines()
my_file.close()
print(read_text)
#print(read_text1)
#%%class 類 和 __init__ 初始化功能
class calculator:
name = 'good calculator'
price = 18
def __init__ (self,name,price,height,width,weight):
self.name = name
self.price = price
self.h = height
self.wi = width
self.we = weight
def add(self,x,y):
result = x + y
print(result)
def minus(self,x,y):
result = x - y
print(result)
def times(self,x,y):
print(x*y)
def divide(self,x,y):
print(x/y)
calcu = calculator('bad calculator',12,30,15,19)
#%% 元組和列表
#tuple list
a_tuple = (12,3,4,5)
another_tuple = 1,2,45
#list
a_list = [12,35,66]
for i in range(len(a_tuple)):
print(a_tuple[i])
for i in range(len(a_list)):
print(a_list[i])
#%%列表
a = [1,2,3,4,5]
a.insert(0,0)
a.remove(2)
print(a.index(0))
#%%多維列表
a = [[1,2,3],[4,5,6],]
print(a[0][1])#2
#%%字典 dictionary
'pear':2,
'orange':3}
del d['pear']
print(d)
d['b'] = 20
d['c'] = 20
print(d)
#%%載入自己的模組 import
#方法一
import time
print(time.localtime())
#方法二
import time as t
print(t.localtime())
#方法三
from time import time,localtime
print(time())
#方法四
from time import*
#%%載入自己的模組
import m1
print(10)
m1.aa()
python爬蟲簡單入門
coding utf 8 from bs4 import beautifulsoup,soupstrainer from threading import lock,thread import sys,time,os from urlparse import urlparse,urljoin fro...
Git簡單使用入門操作
一 git介紹 git是一款免費 開源的分布式版本控制系統,用於敏捷高效地處理任何或小或大的專案。類似svn又有所不同。分布式相比於集中式的最大區別在於開發者可以提交到本地,每個開發者通過轉殖 git clone 在本地機器上拷貝乙個完整的git倉庫。下圖是經典的git開發過程。git的功能特性 從...
簡單的PDO入門操作
1,介紹一下什麼是pdo pdo是php 5新加入的乙個重大功能,因為在php 5以前的php4 php3都是一堆的資料庫擴充套件來跟各個資料庫的連線和處理,什麼 php mysql.dll php pgsql.dll php mssql.dll php sqlite.dll等等擴充套件來連線mys...