Python Learning the next day is a disaster ah, this day was hit, their homework was denied, do not say, write blog is a good habit, to persist, I do not know how to adhere to when. Oh!!!
This day teaching knowledge and the first day of knowledge is not small, the difference is more than the first day of the more detailed (we are two teachers taught, style is not the same), this time also write those relatively fine knowledge points.
Introduction to Python
(1) Your program must have a master file.
(2) For Python, everything is an object, and the object is created based on the class. #似懂非懂, but it's a little bit like that.
Knowledge points
#__divmod__ will print the quotient and remainder of dividing two numbers in tuples.
Example:
>>> age = 13>>> o = age.__divmod__ (7) >>> print O output: (1, 6) #rdivmod divide and replace position >>> age = 13>>> o = age.__rdivmod__ (7) >>> print o output: (0, 7) #__abs__ absolute value >>> age = -13>>> o = AG e.__abs__ () >>> print o13@ second method >>> abs ( -19) 19#__add__ Two number add >>> age = -13>>> o = age._ _add__ >>> Print O21 second method >>>-13 + 3421string str#type can tell if objects belong to those classes
>>> Age = 18
>>> type (age)
<type ' int ' >
#dir can provide the functionality of the object
>>> Age = 18
>>> Print (dir (age)) [' __abs__ ', ' __add__ ', ' __and__ ', ' __class__ ', ' __cmp__ ', ' __coerce__ ' ... #__contains__ whether to include characters >>> name = ' Zzn ' >>> f = name.__contains__ (' zzn ') >>> print Ftrue the second method > >> name = ' zzn ' >>> ' zzn ' in Nametrue#.casefold converts uppercase letters to lowercase name = ' Zzn ' F = name.casefold () print (f) zzn#center Add content on both sides name = ' Zzn ' F = name.center (*, ' * ') print (f) Output: ********zzn********* #conunt statistics have several identical characters name = ' Zzndsfsdfsdsdfsdf ' F = name.count (' z ') print (f) The output is: 2#encode conversion character set conversion binary name = ' Zhang Zhinan ' F = name.encode (' GBK ') print (f) Output: B ' \xd5\xc5\xd6\xbe\xe9\xaa ' #endswith with what start to return truename = ' alex ' F = name.endswith (' e ', 0,3) print (f) Output: TrueImport Module
Simple Introduction
#! /usr/bin/env python
Import Sysprint (SYS.ARGV) #输出这个python文件的完整路径print (sys.version) #输出Python版本输出结果: [' c:/users/wodehuipu/ pycharmprojects/untitled/day2/dict.py ']3.5.1 (v3.5.1:37a07cee5969, Dec 6, 01:54:25) [MSC v.1900 bit (AMD64)]Dictionary#字典的语法:>>> dict = {' name ': ' Zzn ', ' age ': ' + ', ' job ': ' It ', ' sex ': ' o '}>>> dict{' job ': ' It ', ' age ': ' 28 ', ' name ': ' Zzn ', ' sex ': ' O '} #增加key:values>>> dict[' city ' = ' bj ' >>> dict{' job ': ' IT ', ' City ': ' BJ ', ' Age ': ', ' name ': ' Zxn ', ' sex ': ' O '} #查看name >>> dict[' name '] ' ZZN ' #查看keydict. Keys () #修改字典; the ZZN of name Change to zxn>>> dict[' name '] = ' zxn ' >>> dict{' job ': ' IT ', ' age ': ' + ', ' name ': ' Zxn ', ' sex ': ' O '} #删除city >>> dict.pop (' City ') ' BJ ' >>> dict{' jobs ': ' IT ', ' age ': ' + ', ' name ': ' Zxn ', ' sex ': ' O '} #另一种的删除方法 > >> del dict[' sex ']>>> dict{' job ': ' It ', ' age ': ' + ', ' name ': ' Zxn '} #随机删除一组数据 >>> dict{' job ': ' It ' , ' age ': ' + ', ' name ': ' Zzn '}>>> dict.popitem (' job ', ' IT ') >>> dict{' age ': ' + ', ' name ': ' Zzn '} #将dict Converted to a list of the form display >>> dict.items () [(' Age ', ' + '), (' Name ', ' Zzn ')] #查找key, if there is a return to values, there is no return null (none) >>> Dict.get (' age ') ' + ' >>> dict.get (' sss ') &NBSp >>> #添加多个values, if all the values of the dictionary need to be indexed without index >>> dict{' job ': ' IT ', ' age ': ' + ', ' name ' ': ' zxn '}>>> dict[' name ' = ' zzn ', ' zyr ', ' ZZR ' >>> dict{' job ': ' IT ', ' Age ': ' ' ', ' name ': (' zzn ', ' zyr ', ' Zzr ')} #通过has_key returns True if the dictionary has this key otherwise returns false>>> dict{' job ': ' IT ', ' Age ': ' ", ' name ': ' Zxn '}>>> Dict.has_key (' age ') true>>> dict.has_key (' sex ') false# emptying dict>>> dict.clear () >> > dict{} #把列表中的值赋予一个values OK values specified for each list value, or null if not specified >>> list = [' A ', ' B ', ' C ']>>> list[' A ', ' B ', ' C ']>>> Dict.fromkeys (list, ' OK ') {' A ': ' OK ', ' C ': ' OK ', ' B ': ' OK '}>>> dict.fromkeys (list) {' a ': None, ' C ': None, ' B ': none}>>> key = Dict.fromkeys (list, ' yes ') >>> key{' a ': ' Yes ', ' C ': ' Yes ', ' B ': ' Yes ' to return values #查找一个key的记录如果这个key existence, otherwise create a >>> dict{' a ': ' Yes ', ' C ': ' Yes ', ' B ': ' Yes '}>>> Dict.setdefault (' f ', ' no ') ' no ' >>> dict{' a ': 'Yes ', ' C ': ' Yes ', ' B ': ' Yes ', ' F ': ' No '}>>> dict.setdefault (' B ', ' no ') #这我是有b This key so it will return this values ' Yes ' # Create a new dictionary by update if the same key will overwrite the original key>>> dict# original dictionary {' A ': ' Yes ', ' C ': ' Yes ', ' B ': ' Yes ', ' F ': ' NO '}>>> Dcit2 = {' A ': ' Hao ', ' d ': ' Le ', ' w ': ' Yu '} #创建的新的字典 >>> dcit2{' a ': ' Hao ', ' d ': ' Le ', ' w ': ' Yu '}>>> Dict.update (dcit2) >>> dict{' a ': ' Hao ', ' C ': ' Yes ', ' B ': ' Yes ', ' d ': ' Le ', ' w ': ' Yu ', ' F ': ' NO ' #原来字典的a的val UEs is covered by the values of a in the new dictionary dictionary convert to progenitor >>> contacts.items (' 222 ', [' zzn ', ' xed ', ' SSI ']), (' 333 ', [' zxn ', ' DESG ', ' Iuy '), (' 444 ', [' die ', ' kxis ', ' Oen '])] contacts = { ' 111 ': [' zzn ', ' it ', ' sa '], '], ': [' Jack ', ' hr ', ' hr ' ' 113 ': [' Davi ', ' CTO ', ' CTO '] #for i in contacts:# print i, Contacts[i] for k,v in Contacts.items (): Print k,v[[email protected] day2]# python zidian.py 111 [' zzn ', ' it ', ' sa ']113 [' Davi ', ' CTO ', ' CTO ']112 [' Jack ', ' hr ', ' hr '] #遍历字典dict = { &nb Sp ' Name ': ' Zzn ', ' age ': ', ' ' job ': ' IT '}for item in dict: print (item, Dict[item ]) #两种遍历的方法for k,v in Dict.items (): print (k,v) output is: Age 26name zznjob itage 26name zznjob it####
>>> DICR = {' job ': ' IT ', ' name ': ' Zzn ', ' Age ': 12}
>>> Dicr.keys () #查看key
[' Age ', ' job ', ' name ']
>>> dicr.values () #查看元素
[' IT ', ' ZZN ']
>>> Dicr.items () #查看字典
[(' Age ', '), (' Job ', ' IT '), (' Name ', ' Zzn ')]
These are basically new additions, and the jobs are as follows:
1. Blog 2. Shopping Cart Merchandise display, price, purchase, add to cart, payment, not enough money is Python learning the next day of content. This day is really depressed AH!!!!
Python Study the next day