python基本語(yǔ)法練習(xí)記錄

# -*- coding: UTF-8 -*-
# a = int(input())
# if a > 100:
#   print 100
# else:
#   print 0


# print('''
# line1
# line2
#   ''')

# print("growth rate: %d%% %s" % (7,"minping"))

# classmates = ["aaa","bbb","ccc"]
# print(len(classmates))
# classmates.append("ddd")
# classmates.insert(1,"aaa1")
# res = classmates.pop()
# res = classmates.pop(1)
# classmates[1] = "bbbb1"
# L = ["apple",123, True]
# classmates[1] = L
# # print(classmates)
# # print(classmates[1][1])
# classmatessss = ("AAA","BBB","CCC")
# classmates
# # print(classmatessss)#tuple不可變,不能被二次賦值,也沒(méi)有append笨鸡,insert,pop等操作

# t = ('a',('b','c'),['A','B'])
# # print(len(t))
# # t[2][0] = 'a'
# # t[2][1] = 'b'
# # print(t)
# classmates[1] = t
# print(classmates)
# # classmates[1][0] = 'A'
# # classmates[1][1][0] = 'B'
# classmates[1][2][1] = 'b'
# # print(classmates)


# res1 = 'a'
# res2 = 'b'
# te = (res1, res2)
# print(te)
# res2 = 'B'
# print(te)


# classmates = ['a','b','c']
# t = (1, 2, classmates, 4)
# print(t)
# t[2][0] = 'A'
# print(t)
# t[2] = t[2].append('d')
# print(t)


# classmates = ["aaa","bbb","ccc",'ddd']
# print(len(classmates))
# classmates.append("eee")
# print(classmates)
# classmates.insert(1,"aaa1") #指定位置insert藤树,后面的元素順勢(shì)后移
# print(classmates)
# res = classmates.pop()
# print(classmates)
# res = classmates.pop(1)  #指定位置pop,后面的元素順勢(shì)前移
# print(classmates)
# classmates[1] = "bbbb1" #指定位置賦值
# L = ["apple",123, True] #slice里每個(gè)元素類型可以不一樣
# classmates[1] = L #slice里的元素也可以為slice
# print(classmates)


# birth = input('birth: ')
# birth = int(birth)
# if birth < 2000:
#     print('00前')
# else:
#     print('00后')

# name = ['a','b','c']
# for k in name:
#   print(k)
# sums = 0
# num = 99
# while num > 0:
#   if num%2 == 0:
#       continue
#   sums += num
#   num -=1
#   if num == 95:
#       break
# # nums = list(range(101))
# # for num in nums:
# #     sums += num
# print(sums)

# d = {'minping':99, 'shuxin':98}
# print(d)
# print(d["minping"])
# print(d.get("minping1"))
# d.pop("minping")
# print(d)

# s = set([1,1,1,2,3,2])
# print(s)
# s.add(4)
# s.add(-1)
# print(s)
# s.remove(3)
# print(s)
# s.remove(-2)
# print(s)
# s1 = set([1,2,3])
# s2 = set([2,3,4])

# # print(s1 & s2) #交集
# # print(s1 | s2) #并集
# # print(s1 - s2) #差集
# s1.add([1,2])
# print(s1)

# print(max(1,2,3))

# def my_abs(x):
#   if not isinstance(x,(int,float)):
#       raise TypeError('bad param type')
#   if x >= 0:
#       return x
#   return -x



# def nop():
#   pass

# ddd = my_abs
# print(ddd('A'))

# import math

# def move(x, y, step, angle=0):
#   nx = x + step*math.cos(angle)
#   ny = y - step*math.sin(angle)
#   return nx, ny
    

# x, y = move(100, 100, 60, math.pi/6)
# print(x, y)

# val = move(100, 100, 60, math.pi/6)
# print(val)

# def power(x, n=2):
#   if not isinstance(x, (int, float)):
#       raise TypeError('input param type error, must be a int or float')
#   res = 1
#   while n > 0:
#       res = res * x
#       n -= 1
#   return res


# print(power(3,2))
# print(power(5))

# def stuinfo(name, gender, age=6, city='Beijing'):
#   print('name:', name)
#   print('gender:', gender)
#   print('age:', age)
#   print('city:', city)

# stuinfo('minp', 'male', city='shanghai')

# def add_end(l=[]):
#   l.append('end')
#   return l

# print(add_end([1,2,3]))
# print(add_end(['x','y','z']))
# print(add_end())
# print(add_end())
# print(add_end())

# def calc(*numbers):
#   sums = 0
#   for num in numbers:
#       sums += num
#   return sums

# res1 = calc(1,2,3) #傳入多個(gè)參數(shù)
# res2 = calc(*[1,2,3])  #傳入一個(gè)list
# res3 = calc(*(1,2,3))  #傳入一個(gè)tuple

# print(res1)
# print(res2)
# print(res3)

# def person(name, age, **kw):
#   print('name is :', name, 'age is :', age, 'other is :',kw)

# person('Michael', 30)
# person('Bob', 35, city='Beijing')
# person('Adam', 45, gender='M', job='Engineer')

# from collections import Iterable


# extra = {'city':'Beijing', 'job':'Engineer'}
# extra = '123'
# if (isinstance(extra, Iterable)):
#   for v in extra:
#       print(v)
# else:
#   print("eeee")
# person('Jack', 24, **extra)


# val = [(1,1), (2,4), (3,9)]

# for x, y in val:
#   print(x,"ddd", y)

# val = [x*x for x in range(2,11) if x %2 == 0]
# print(val)

# val = [m+n for m in 'abc' for n in '123']
# print(val)

# val = [m+n+p for m in 'abc' for n in '123' for p in 'IVM']
# print(val)

# import os

# val = [d for d in os.listdir('.')]
# print(val)

# d = {'city':'Beijing', 'job':'Employer'}
# val = [k+'='+v for k,v in d.items()]
# print(val)

# L = ['Hello', 'World', 'IBM', 'Apple']
# val = [v.lower() for v in L]
# print(val)

# g = (x*x for x in range(1,3))
# # print(next(g))
# # print(next(g))
# # print(next(g))
# # print(next(g))
# for v in g:
#   print(v)

# def fib(max):
#   a, b = 1, 1
#   while b < max:
#       yield b 
#       a, b = b, a+b
#   return 'done'

# f = fib(6)

# while True:
#   try:
#       v = next(f)
#       print(v)
#   except StopIteration as e:
#       print('Gengerator return value is: ',e.value)
#       break

# def f(x):
#   return x*x

# r = map(f, list(range(10)))
# print(list(r))
# # for v in r:
# #     print(v)

# print(list(map(str, [1,2,3,4,5])))

# def add(x, y):
#   return x+y

# r = reduce(add, [1,2,3,4,5])
# print(r)

# def fn(x, y):
#   return 10*x +y

# def str2int(strstr):
#   return reduce(fn,list(map(int, list(strstr))))

# print(str2int('123456789'))

# def is_odd(n):
#   return n%2 == 0

# r = filter(is_odd,[1,2,3,4,5])
# print(next(r))


# def _odder():
#   n = 3
#   while True:
#       yield n 
#       n += 2

# def primes():
#   yield 2
#   it = _odder() 
#   while True:
#       v = next(it)
#       yield v 

# p = primes()
# print(p)
# print(next(p))
# print(next(p))


# r = sorted([1,5,-3,6,2], key=abs)
# print(r)

# l = ['bob', 'about', 'Zoo', 'Credit']
# r = sorted(l, key = str.lower, reverse = True)
# print(r)

# def lazy_sum(*args):
#   def my_sum():
#       sums = 0
#       for v in args:
#           sums += v
#       return sums
#   return my_sum

# r = lazy_sum(*[1,2,3,4,5])
# print(r)
# print(r())

# def count():
#   fs = []
#   for i in range(1,4):
#       def f():
#           return i*i
#       fs.append(f)
#   return fs 

# f1,f2,f3 = count()
# print(f1())
# print(f2())
# print(f3())



# def count_new():
#   fs = []
#   def f(i):
#       def g():
#           return i*i
#       return g 
#   for i in range(1,4):
#       fs.append(f(i))
#   return fs

# f1,f2,f3 = count_new()
# print(f1())
# print(f2())
# print(f3())

# f = lambda x: x*x
# print(f)

# ' a test module '

# __author__ = 'mp'

# import sys



# # def test():
# #     arg = sys.argv
# #     if len(arg) == 1:
# #         print('hello world')
# #     elif len(arg) == 3:
# #         print('Hello, %s %s' % (arg[1], arg[2]))
# #     else:
# #         print('too many param')

# def _private1(name):
#   return 'hello %s' % name

# def _private2(name):
#   return 'hi %s' % name 

# def greeting(name):
#   if len(name) < 3:
#       print _private1(name)
#   else:
#       print _private2(name)
#   return
    

# if __name__=='__main__':
#   greeting("shuxin")

# class Student(object):
#   def __init__(self, name, score):
#       self.__name = name 
#       self.__score = score

#   def print_score(self):
#       print('%s:%s' % (self.__name, self.__score))

# bart = Student("minping", 99)
# lisa = Student("shuxin", 100)
# bart.__name = 'ddd'
# print(bart.__name)
# print(bart.Student.__name)
# # lisa.print_score()

# class Animal(object):
#   def run(self):
#       print('Animal is running...')

# class Dog(Animal):
#   def run(self):
#       print('Dog is running...')

# class Cat(Animal):
#   def run(self):
#       print('Cat is running...')

# dog = Dog()
# dog.run()
# cat = Cat()
# cat.run()

# print(isinstance(dog, Dog))
# print(isinstance(dog, Animal))
# print(isinstance(dog, Cat))

# def run_t(animal):
#   animal.run()

# run_t(Animal())
# run_t(Dog())
# run_t(Cat())

# print(dir(cat))

# import logging

# def foo(s):
#   return 10/int(s)

# def main():
#   try:
#       foo(0)
#   except Exception as e:
#       logging.exception(e)

# main()
# print('END')

# with open('2.py', 'a') as f:
#   res = f.write('shuxin')

# with open('2.py') as f:
#   res = f.read()
#   print(res)

# from io import BytesIO as StringIO
# f = StringIO()
# f.write('minping')
# print(f.read())
# while True:
#   s = f.readline()
#   if s == '':
#       break
#   print(s)


# from io import BytesIO
# f = BytesIO()
# f.write('中文'.encode('utf-8'))
# print(f.getvalue())

# import os
# print(os.environ)

# import json
# d = {'name':'minping', 'age':20}
# r = json.dumps(d)
# print(r)
# print(isinstance(r, dict))

# re = json.loads(r)
# print(re)
# print(isinstance(re, dict))


# import json
# class Student(object):
#   def __init__(self, name, score):
#       self.name = name
#       self.score = score

# # def obj2json(obj1):
# #         return {'name':obj1.name, 'score':obj1.score}

# s = Student('shuxin', 99)
# print(json.dumps(s, default = lambda obj: obj.__dict__))

from datetime import datetime
now = datetime.now()
# print(now)
# dt = datetime(2013, 12, 12, 14, 15, 00)
# print(dt.timestamp())
print(datetime.fromtimestamp(1386828900.0))

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末拓萌,一起剝皮案震驚了整個(gè)濱河市岁钓,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌微王,老刑警劉巖屡限,帶你破解...
    沈念sama閱讀 219,539評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異炕倘,居然都是意外死亡钧大,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,594評(píng)論 3 396
  • 文/潘曉璐 我一進(jìn)店門罩旋,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)啊央,“玉大人眶诈,你說(shuō)我怎么就攤上這事×哟欤” “怎么了册养?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,871評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵东帅,是天一觀的道長(zhǎng)压固。 經(jīng)常有香客問(wèn)我,道長(zhǎng)靠闭,這世上最難降的妖魔是什么帐我? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,963評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮愧膀,結(jié)果婚禮上拦键,老公的妹妹穿的比我還像新娘。我一直安慰自己檩淋,他們只是感情好芬为,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,984評(píng)論 6 393
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著蟀悦,像睡著了一般媚朦。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上日戈,一...
    開(kāi)封第一講書(shū)人閱讀 51,763評(píng)論 1 307
  • 那天询张,我揣著相機(jī)與錄音,去河邊找鬼浙炼。 笑死份氧,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的弯屈。 我是一名探鬼主播蜗帜,決...
    沈念sama閱讀 40,468評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼资厉!你這毒婦竟也來(lái)了厅缺?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,357評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤酌住,失蹤者是張志新(化名)和其女友劉穎店归,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體酪我,經(jīng)...
    沈念sama閱讀 45,850評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡消痛,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,002評(píng)論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了都哭。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片秩伞。...
    茶點(diǎn)故事閱讀 40,144評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡逞带,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出纱新,到底是詐尸還是另有隱情展氓,我是刑警寧澤,帶...
    沈念sama閱讀 35,823評(píng)論 5 346
  • 正文 年R本政府宣布脸爱,位于F島的核電站遇汞,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏簿废。R本人自食惡果不足惜空入,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,483評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望族檬。 院中可真熱鬧歪赢,春花似錦、人聲如沸单料。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,026評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)扫尖。三九已至白对,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間藏斩,已是汗流浹背躏结。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,150評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留狰域,地道東北人媳拴。 一個(gè)月前我還...
    沈念sama閱讀 48,415評(píng)論 3 373
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像兆览,于是被迫代替她去往敵國(guó)和親屈溉。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,092評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容