Python 初体验 基本语法

初学python,把笔记做一个记录,便于以后使用和查阅

'''
Created on 2017年8月3日

@author: Administrator

1:基础语法
'''

print('hello world')
print("Hello, Python!")

# 行和缩进
if True:
    print("True")
else:
  print("False")
  
# 多行语句
total = 'item_one ' + \
        'item_two ' + \
        'item_three '
print(total)   
days = ['Monday', 'Tuesday', 'Wednesday',
    'Thursday', 'Friday']
print(days)

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

# 注释
# 第一个注释
print("Hello, Python!")  # 第二个注释
'''
这是多行注释,使用单引号。
这是多行注释,使用单引号。
这是多行注释,使用单引号。
'''

"""
这是多行注释,使用双引号。
这是多行注释,使用双引号。
这是多行注释,使用双引号。
"""

# 等待用户输入
# str = input("\n\nPress the enter key to exit.")
# print("input is "+str)

# 同一行显示多条语句,语句之间使用分号(;)分割
import sys; x = 'runoob'; sys.stdout.write(x + '\n')

# Print 输出
# print 默认输出是换行的,如果要实现不换行需要在变量末尾加上逗号:
x = "a"
y = "b"
# 换行输出
print(x)
print(y)

print('---------')
# 不换行输出(貌似在这里不起作用)
print(x),
print(y),

print('hello,', end='')
print('world!')

# 多个语句构成代码组
if x=="a":
    print("x==a")
elif x!="a":
    print("x!=a")

# 命令行参数
'''
$ python -h 
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ... 
Options and arguments (and corresponding environment variables): 
-c cmd : program passed in as string (terminates option list) 
-d     : debug output from parser (also PYTHONDEBUG=x) 
-E     : ignore environment variables (such as PYTHONPATH) 
-h     : print this help message and exit 
'''


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值