//this is my first day to study python, in order to review, every day i will make notes (2016/7/31)

1. In python , there are many bulit-in funcation. you can use follow to find out hou many built-in funcation:

dir(__builtins__)

if you want get BIF detail, you can use follow code:

help(……)    such as help(input),int()

2. In python, you should be care to indent, if not , it will appear a lots error.

such as follow ,because indent error ,it will appear an error:

temp = input('input a num you want:')
    guess = int(temp)
    if guess == 8:
    print('you are right')
    else:
           print('you are wrong')

3. In python , when you define variable ,uppercase and lowercase is different.

such as:

temp = 'roy'

Temp = 'wyg'

temp and Temp is not same variable

4. In python , if you want to use ' in a string ,you can user escape charcters : \

such as:

print('Let\'s go!')

5. In python , origin string is userful , maybe the follow result is not  you except

such as :

str = 'c:\now\data'

print(str)

result is :

c:

ow\data

you can solve this problem by str = r'c:\now\data' ,this code is equal to str = 'c:\\now\\data'

when you print(str), the result will be c:\now\data

6. In python , if a string , you want to change row ,you can user '''  ,if you not user ''' and change row ,it will appear an error

such as:

str = '''this

is

me'''

print(str)

the result is :

this

is

me

7. In python , import module , such as if you want  a rand num , range is 1-10 and type is int ,how to achieve it

import random

randnum = random.randint(1,10)

//this is second day to study python(2016/8/1)

8. In python , we can see 'e' as 10

such as:

1.5e4 == 15000.0

9. In python , type conversion is userful , the follow is base conversion

float or string -> int

such as :

a = '26'    b = int(a)   print(b) -> 26

a = 'qq'    b = int(a)   error

a = 3.14  b = int(a)    print(b) -> 3

----------------------------------------

int or string -> float

such as:

a = '26'  b = float(b)  print(b) -> 26.0

a = 'qq'  b = float(b)  error

a = 26   b = float(b)   print(b) -> 26.0

------------------------------------------

int or float -> str

such as:

a = 26  b = str(a)  print(b) -> '26'

a = 3.14  b = str(a) print(b) -> '3.14'

a = 5e19 b = str(a) print(b) -> '5e+19'

sometimes, we need to be care to str,

such as:

str = 'I like apple'

print(str) -> 'I like apple'

but if it is c = str(5e19)  ,it will appear an error ,because str is BIF ,we define str again , it will have new means, so it will have error

10. In python ,we can get the type of variable

such as:

a = 'qq'

type(a) -> <class 'str' at 0x----->

a = 3.0

type(a) -> <class 'float' at 0x--->

a = True

type(a) -> <class 'bool' at 0x--->

we recommand follow:

a = 'roy'

isinstance(a, str)  -> True

isinstance(a, int)  -> False

but sometimes you need to know it maybe account an error:

TypeError: isinstance() arg 2 must be a type or tuple of types

the reason is may you define str before, In python ,you can change built-in funcation, so when you define variable ,you should try to avoid user special    chararctes. such as try not to use BIF.

11. In python , arithmetic operators has +   -   *   /   **   //   %

a += 4 <==> a = a + 4

a = 2

b = 3

a / b -> 0.6666666666666666
      a // b -> 0

b // a -> 1

a % b -> 2

b % a -> 1

a * b -> 8

b ** a -> 9

12. In python , logical operators includes and , or , not

such as:

not Ture

False

13. In python , if and else how to use:

score = int(input('please input score:'))

if 90<= score <= 100:

print('A')

elif 80<= score < 90:

print('B')

elif 60<= score < 80:

print('C')

else:

print('D')

14.  trinocular operator

small = x if x < y else y

->

x, y = 4, 5

if x < y:

small = x

else:

small = y

15. assert ,when condication is false , it will have assertionerror

such as:

assert 3 > 4

>>> assert 3>4
      Traceback (most recent call last):
      File "<pyshell#1>", line 1, in <module>
      assert 3>4
      AssertionError

//third day study python (2016/8/2)

16. In python , how to achieve 'for' loop:

for target in expression:

loop body

such as:

string = 'roy'

for i  in  string:

print(i)

->

r

o

y

students = ['wyg' , 'roy]

for each in students:

print(each,len(each))

17. In python , range() is often combined with for loop , what's range()

range([start,] stop [, step = 1])  // three para

[] represent select

step = 1 represent by default step is 1

so it is from start to stop number list

range(3) -> range(0,3)

list(range(4)) -> [0, 1, 2, 3]

for i in range(2,5):

print(i)

result is :2  3   4

for i in range(1,10,4):

print(i)

result is :1 5  9

18. In python , there are also have break and continue

continue skip current loop

break end loop

19.  In python , there are no array ,but have list and more power

such as:

mixType = [1, 'roy', 3.14, [5, 6]]

we can also create an empty list:

empty = []

how to add content to list:

empty.appen(3)  -> 3

or

empty.extend([3, 6, 9]) -> 3  3  6  9

or

empty.insert(0, 'aaa') -> 3 'aaa  3  6  9

how to get value according to subscript:

empty[0] -> 3

how to delete value

empty.remove(9) -> 3 'aaa' 3 6

or

del temp[1]  -> 3 3 6

if you want to delete from memary , you can use del temp

or

temp.pop() -> [3, 3]

you also can pop value according to subscript

such as :temp.pop(1)

slice is useful ,you can achieve amazing thing:

such as :

aaa = [1, 2, 3, 4, 5, 6]

aaa[1:4] -> [2,3,4]

aaa[:3] -> [1,2,3]

aaa[1:] -> [2,3,4,5,6]

aaa[:] = [1,2,3,4,5,6]

aaa -> [1,2,3,4,5,6]

20. In python , how to compare to list

list1 = [123,456]

list2 = [234,345]

list1 > list2

-> False

list1 + list2

-> [123,456,234,345]

list1 * 2

-> [123,456,123,456]

456 in list1

-> True

456 not in list1

-> Falsse

list3 = [1,2,[3,4]]

3 in list3

-> False

3 in list3[2]

-> True

list3[2][1]

-> 4

21. In python , how many method of list

we can use dir(list) to find out it

now i show some common method:

a = [12, 13, 13, 14]

a.count(13)

-> 2

a.index(14)

-> 3

a.reverse()

-> [14, 13, 13, 13]

b = [2, 1, 3 ,5, 4]

b.sort()

-> [1, 2, 3, 4, 5]

b.sort(reverse = True)

-> [5, 4, 3, 2, 1]

22.  In python , there are also have an important type tuple

if you define a tuple , you can't change it , but if it is list ,you can modify ,insert ,delete value.

now that we have list , why we need tuple , i guess , they are like array and mutablearray in oc.

tuple1 = (1,2,3,4,5,6,7)

tuple1[1]

-> 2

tuple1[:]

-> (1,2,3,4,5,6,7)

but we can't modify it , such as:

tuple1[1] = 10

-> error

now we can some special thing :

temp = (1)

-> 1

type(temp)

-> int

temp = 1, 2

type(temp)

-> tuple

so if tuple is one number , we should user temp = (1,) or temp = 1,  then type(temp) can get tuple

now we can see an interesting question:

6 * (6) -> 36

6 * (6,) -> (6, 6, 6, 6, 6, 6)

how to add a new value to duple:

such as:

temp = ('roy' ,'wyg' ,'tom')

temp = temp[:2] + ('jim',) + temp[2:]

-> ('roy' ,'wyg', 'jim' ,'tom')

we can use del temp to delete all temp

duple we can user + , * , = , in , not in , and , or etc.

23. In python , str is an important type. it is similar to duple.

str1 = 'my name is roy'

str1[:6]

-> 'my nam'

str1[3]

-> n

str1[:6] + 'ttt' + str1[6:]

-> 'my namttte is roy'

str2 = 'roy'

str2.capitalize()

-> 'Roy'

str3 = 'ROY'

str3.casefold()

-> 'roy'

str4 = 'roy'

str4.center(6)

-> '  roy  '

str5 = 'royroy'

str5.count('y')

-> 2

str6 = 'roy'

str6.endswith('oy')

-> True

str7 = 'I\tlove\tyou'

str7.expandtabs()

-> 'I       love    you'
     str8 = 'abcd'

str8.find('d')

-> 3

str8.find('e')

-> -1

str8.index('d')

-> 3

str8.index('e')

-> error

there are also other method:

isalnum()  #如果字符串中至少有一个字符并且所有字符都是字母或数字返回True

isalpha()   #如果字符串中至少有一个字符并且所有字符都是字母返回True

isdecimal()#如果字符串只包含十进制数字返回True

isdigit()    #如果字符串中只包含数字返回True

islower()  #如果字符串中至少包含一个区分大小写的字符,并且这些字符都是小写,返回True

isnumeric() #如果字符串中只包含数字字符,返回True

isspace()  #如果字符串中只包含空格,返回True

istitle()    #如果字符串是标题化,所有单词大写开始,其余小写,返回True

isupper() #如果字符串中至少包含一个区分大小写的字符,并且这些字符都是大写,返回True
     lstrip()    #去掉字符串中左边所有空格

rstrip()   #去掉字符串右边所有空格

join(sub) #以字符串作为分隔符,插入到sub中所有的字符之间

ljust(width) #返回一个左对齐字符串,并使用空格填充至width长度

lower()   #大写字符转化为小写

partition(sub) #找到子字符串sub,把字符串分割一个3元组,如不包含sub,则返回元字符串

replace(old,new[,count]) #把old换成new,如果count指定,则替换不超过count次

rfind(sub,[,start,[,end]) #类find,从右边开始查找

rindex(sub,[,start],[,end])  #类index,从右边开始

rpartition(sub) #类似partition(),从右边开始查找

rjust(width) #右对齐

split(sep = None,maxsplit = -1) #不带参数是以空格为分隔符,如maxsplit有设置,则分割成maxsplit个子字符串,返回列表

splitlines(([keepends])) #按照\n分隔,返回一个包含各行作为元素的列表,如制定keepends,返回前keepends行

swapcase() #翻转字符串中的大小写

title()  #返回标题话

startswith(prefix[,start][,ends]) #是否以prefix开始,返回 True

strip([chars])   #删除字符串前边和后边所有空格

upper()

translate(table) #替换字符

zfil(width) #右边对齐,前边0填充

Python Base One的更多相关文章

  1. Python Base of Scientific Stack(Python基础之科学栈)

    Python Base of Scientific Stack(Python基础之科学栈) 1. Python的科学栈(Scientific Stack) NumPy NumPy提供度多维数组对象,以 ...

  2. Python Base Four

    35. In python, file operation syntax is similar to c. open(file,'r',……) //the first parameters is ne ...

  3. Python Base Five

    // 8 day(2016/8/11) 38. In python , it is oop. class Baskball:         def setName(self, name):      ...

  4. Python Base Three

    //sixth day to study python(2016/8/7) 32. In python , there are have an special type dictionary , it ...

  5. Python Base Two

    //fourth day to study python 24. In python , how to create funcation. we can use def to define funca ...

  6. 2019-04-18 Python Base 1

    C:\Users\Jeffery1u>python Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64 ...

  7. python base 64

    python中base64编码与解码   引言: 在一些项目中,接口的报文是通过base64加密传输的,所以在进行接口自动化时,需要对所传的参数进行base64编码,对拿到的响应报文进行解码: Bas ...

  8. Python Base HTTP Server

    import BaseHTTPServer import cgi, random, sys MESSAGES = [ "That's as maybe, it's still a frog. ...

  9. 基于Python+协程+多进程的通用弱密码扫描器

    听说不想扯淡的程序猿,不是一只好猿.所以今天来扯扯淡,不贴代码,只讲设计思想. 0x00 起 - 初始设计 我们的目标是设计一枚通用的弱密码扫描器,基本功能是针对不同类型的弱密码,可方便的扩展,比如添 ...

随机推荐

  1. Python socket 粘包

    目录 1 TCP的三次握手四次挥手 0 1.1 三次握手 1 1.2 四次挥手 2 2 粘包现象 3 2.1 基于TCP制作远程执行命令操作(win服务端) 4 2.1 基于TCP制作远程执行命令操作 ...

  2. CodePlus #4 最短路

    题目传送门 北极为什么会有企鹅啊,而且北纬91°在哪啊? 关键在建图 因为任意两个城市间都可以互相到达,再加上还有"快捷通道",光是建图就已经\(\rm{T}\)了-- 但这题给了 ...

  3. JQuery EasyUI学习记录(四)

    1.EasyUI中的validatebox使用 提供的校验规则: 1.非空校验required="required" 2.使用validType指定 email: 正则表达式匹配电 ...

  4. java基础——快速排序

    今天又把以前学的快速排序拿出来回忆一下 高快省的排序算法 有没有既不浪费空间又可以快一点的排序算法呢?那就是“快速排序”啦!光听这个名字是不是就觉得很高端呢. 假设我们现在对“6 1 2 7 9 3 ...

  5. 【线段树分治 01背包】loj#6515. 「雅礼集训 2018 Day10」贪玩蓝月

    考试时候怎么就是没想到线段树分治呢? 题目描述 <贪玩蓝月>是目前最火爆的网页游戏.在游戏中每个角色都有若干装备,每件装备有一个特征值 $w$ 和一个战斗力 $v$ .在每种特定的情况下, ...

  6. 到底该如何理解DevOps这个词

    炒了8年的概念,到底该如何理解DevOps这个词? 转载本文需注明出处:EAII企业架构创新研究院,违者必究.如需加入微信群参与微课堂.架构设计与讨论直播请直接回复公众号:“EAII企业架构创新研究院 ...

  7. 在 Ubuntu 环境下实现插入鼠标自动关闭触摸板

    Ubuntu 以及其他衍生版本,如 Linux Mint 等等都可以用官方的 PPA 来安装"触摸板指示"应用程序.打开一个终端,运行以下命令: sudo add-apt-repo ...

  8. Ajax原生代码

    Ajax传数据有两种方式:get/post.下面是前台的get/post方式的代码. //------------原生--------- function AjaxGET(){ //第一步 调用Aja ...

  9. memcache 协议 && Golang实现

    https://github.com/quguolin/memcache 一:Error ERROR\r\n 客户端发送了一个不存在的命令 CLIENT_ERROR\r\n 客户端发送了一个不符合协议 ...

  10. Python爬虫二

    常见的反爬手段和解决思路 1)明确反反爬的主要思路 反反爬的主要思路就是尽可能的去模拟浏览器,浏览器在如何操作,代码中就如何去实现;浏览器先请求了地址url1,保留了cookie在本地,之后请求地址u ...