the shortcut of remark:Ctrl+/ 

print function:

1.print("string")

2.print("string"*repeat times)

range function:

        range(start,stop[,step])      # []represent not neccessary

                                                         step appear along with start,

                                                        step represent the plus/minus during iteration,

                                                         the default of start is zero

Variable:

1.no need to specify variable types

2.Definition:

        a.name = values;

        b.name =False /True  #bool(""/0/[]/None)  are regared as False.

        c.name ="string"/'string'/"'mutiple lines of strings"'

#fine with initializing two variable in the same line. ex:  x,y=1,2 or x=y=1 

Arrays:

1.Definition: nameOfArray=[values1,values2,]#calculate the length of array:len(name)

2.Reference: array  [ranking]#ranking from 0 to len-1

                       for i in nameofarray:#use looping to lterating over an array

                        array[rank1:rank2]#lterating from rank1 to rank2-1

                        array[rank:]#from rank to the final

                         array[rank:-1]#from rank to final-1 

3.Operatation: a.add an element :array.append(element)

                         b.delete an element :array.pop(rank)#delete the point element

                                                            array.remove(values)#delete the values at its first                                                                 appearance

                        c.insert an element:array.insert(index,object)

                        d.count specific elements: array.count(values)

                         e.delete the space:array.strip()#strip/rstrip/lstrip

Transforming types:

        int(),float(),bool()#variable in the bracket

Loops:

        1.for;

             string:  for x in "Python":

                                print(x)

             list:        for x in [ 'a','b','c']:

                                       print(x)           

names=["mike","jordan"]
for i in names:
    if i.startswith("j"):
        print("found")
        break
else:#when iterating all the element in the loops
        print("not found")

         2.while:

                  

guess=0
answer=5
while guess!=answer:
    guess=int(input("guess:"))
else:
    pass

                                   

作者:wys710

物联沃分享整理
物联沃-IOTWORD物联网 » basic python learning 1

发表回复