代码改变世界

python 注释

2017-02-15 15:27  fkk  阅读(245)  评论(0)    收藏  举报

 当行注释:#被注释内容

#name = "Meng"

多行注释:“”“被注释内容”“”或’‘’被注释内容‘’‘

'''age = int(input("age: "))
if age < 21:
    print("你不能抽烟!")
print("这句不在if语句块中")'''


四:单引号,双引号和三引号

  在一般情况下单引号和双引号是没有区别的,但是如果字符串中有相同的字符时需要使用\进行转义,例如:

 print("hello word")
2 print('hello word')

1和2结果都是hello word

3 print("I\'m")
4 print("I'm")

3和4的结果都是I'm

5 print('I"m')
6 print('I\"m')

5和6的结果都是I“m

三引号和它们不同之处:”所见即所得“,对于多行字符串时用三引号更直观点(若用单引号或双引号需要进行转义),例如:

print('''my name is Meng,
hello word,
I like python.''')

结果是:

my name is Meng,

hello word,

I like python.

 

用户输入:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
name = input("What is your name? ") #将用户输入的内容复制给name变量
print("hello " + name )

以上结果为:

What is your name? Meng #用户输入的内容
hello Meng