Python学习笔记-基础语法

多行代码

Python语句中一般以新行作为为语句的结束符。

但是我们可以使用斜杠( \)将一行的语句分为多行显示,如下所示:

#多行代码
item_one=1;
item_two=2;
item_three=3;

total = item_one + \
        item_two + \
        item_three
print (total)

括号内不需要斜杠  [], {} 或 ()

Python 引号

word = 'word'
sentence = "这是一个句子。"
paragraph = """这是一个段落。
包含了多个语句"""

print (word)
print (sentence)
print (paragraph)

Python注释

 1、python中单行注释采用 # 开头。

#注释

2、python 中多行注释使用三个单引号(''')或三个双引号(""")。

'''
这是多行注释,使用单引号。
这是多行注释,使用单引号。
这是多行注释,使用单引号。
'''
View Code

3、等待用户输入

item_one= raw_input("please input a number:")
item_two=2;

print item_one
print item_one + '+2=' + str(int(item_one)+item_two)
View Code

Print 输出

x="a"
y="b"
# 换行输出
print (x)
print (y)

print ('---------')
# 不换行输出
print (x),
print (y),

# 不换行输出
print (x,y)
View Code

 

posted @ 2017-11-14 15:01  帆帆Evan  阅读(212)  评论(0编辑  收藏  举报