Python日常1

2018-07-27 06:27:59来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

1. 关键字

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
>>> 

2. print

-----------------print换行问题----------------------

#!/usr/bin/python

i = 1
while i <= 25:
    print('$', end="5")
    if i%5==0:
        print("  m")
    i += 1
print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")    
a = 1
while a <= 25:
    print('#', end="")#print默认每次打印会换行,加上end=""可以连着打印
    if a%5==0:
        print("")
    a += 1
print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")        
a = 1
while a <= 25:
    print('#', end="")
    if a%5==0:
        print("\n")#另起一行打印回车,如果只是要换行则是print("\n",end="")
    a += 1

运行结果如下:

-------------------print打印变量-----------------------

 

#!/usr/bin/python

name = '哆啦A梦'
birth_year = 2122
birth_month = "September"
birth_day = 3
print('He was born on %s %d, %d.'%(birth_month, birth_day, birth_year))
print('His name is %s'%name)

 

运行结果:

另外:

print('good'*10)
#结果为:goodgoodgoodgoodgoodgoodgoodgoodgoodgood

 

3. 注释

 

#单行注释
'''多行注释
   good
   bad       
   but
   oh'''

"""多行注释
We have many hobbies.
Nice.
"""

 

4.运算符

 

#!/usr/bin/python

print(2**3)#**表示幂,结果为8
print(7//3)#整除,结果为2

 

 

 

 

 

 

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:python3-开发进阶Django-form组件中model form组件

下一篇:Python用webdriver实现微博批量自动关注