Day 4 python learning Notes

1 code style

    About 1.1 indentation, tab key and the spacebar do not mix

    1.2 blank line

    1.3 single line of characters is not too long, not more than 79 recommendations

    1.4 or more in the output line of code or two rows, the input end of the line does not need specialized adapters symbol

2 python assignment

    2.1 a single object assigned to individual variables, such as:

a=12

 2.2 a single object assigned to a plurality of variables, such as:

a=b=c=12

    2.3 assignment sequence (a plurality of objects assigned to a plurality of variables and the number of objects is equal to the number of variables), as:

a,b,c=2,12,4

  If a = 2, b = 12, c = 4, may be used in the following manner:

(a,b,c)=(2,12,4)

  or

[a,b,c]=[2,12,4]

    2.4 unpacking assignment spreading sequence (a plurality of objects assigned to a plurality of variables and the number of objects and not equal to the number of variables), as:

a,b,*c=’youpin’

  则a=’y’,b=’o’,c=’upin’

3 print () function

3.1 separator, sep = 'separator'

    3.2 terminator, end = 'terminator'

    3.3 save printing value, file = 'file'

    such as:

ur1=’ab’,ur2=’cd’,ur3=’efg’

print(ur1,ur2,ur3,sep=’|’,end=’…\n’,file=open(‘result.txt’,’w’,encoding=’utf8’))

And judging the truth of a list of strings 4

    For a list of strings or, when the containing element is true, otherwise false

5 ternary operator

a=x if Y else Z

Guess you like

Origin www.cnblogs.com/zhuome/p/11306250.html