2021-01-01

2021-01-01  本文已影响0人  如丝如梦

一两年前已经考虑入门一种编程语言了。最后选定的是python,网课也报了,书也买了。但是由于各种借口和原因,半途而废了。今年再拾起来,告诉自己,python也必须每天进步一点点。

变量的命名规范:

1,只能是一个词 2,只能包含字母,数字和下划线 3,不能以数字开头 4,尽量描述包涵的数据内容


>>>>>> 17//3 # "//"除法运算后的整数部分

5


>>> 17%3 # "%"除法运算后的余数部分

2


>>> 5**2 #  "%"次方运算

25


>>> tax=12.5/100

>>> price=100.50

>>> price*tax

12.5625

>>> price+_  #  最后一个打印的表达式会被分配给"-"

113.0625

>>> round(_,2)

113.06


>>> 'doesn\'t' #  上面这种为了避免引起混乱,在中间的单引号前需要使用转义字符“\”

"doesn't"

>>> "doesn't"

"doesn't"


>>> print('C:\some\name') # \n 意味着换行。

C:\some

ame

>>> print('''C:\some 

ame''')

C:\some

ame

>>> print(r'C:\some\name') # 避免“\”前缀的字符被解释为特殊字符,可在首个单引号前加“r”

C:\some\name

>>> a=1

>>> b= '人我编程累碎掉的节操满地堆'

>>> c=2

>>> d='眼是bug相随我只求今日能早归'

>>> print(str(a)+b+"\n"+str(c)+d)

1人我编程累碎掉的节操满地堆

2眼是bug相随我只求今日能早归

>>> print(str(a)+b+'''

'''+str(c)+d)

1人我编程累碎掉的节操满地堆

2眼是bug相随我只求今日能早归


>>> 3*'un'+'ium'

'unununium'

>>> 'Py''thon'

'Python'

>>> text = ('Put several strings within parentheses ''to have them joined together.')

>>> text

'Put several strings within parentheses to have them joined together.'


>>> word = 'Python'  # 正数从0开始,负数从-1开始。

>>> word[0]

'P'

>>> word[5]

'n'

>>> word[-1]

'n'

>>> word[-6]

'P'

>>> word[:2]+'py'

'Pypy'


>>> s='supercalifragilisticexpialidocious'

>>> len(s) #内置函数len()返回字符串的长度。

34

>>> letters=['a','b','c','d']

>>> len(letters)

4


print内部使用三引号'''(连续输入三个单引号)可以实现跨行输出。

跟\n 的作用一样。

上一篇 下一篇

猜你喜欢

热点阅读