python3基础-3---语法说明

命令行参数

可以使用python -h 来查看
[root@openvpn–test Python-3.7.6]# python -h
usage: python [option] … [-c cmd | -m mod | file | -] [arg] …
Options and arguments (and corresponding environment variables):
-b : issue warnings about str(bytes_instance), str(bytearray_instance)
and comparing bytes/bytearray with str. (-bb: issue errors)
-B : don’t write .pyc files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d : debug output from parser; also PYTHONDEBUG=x
-E : ignore PYTHON* environment variables (such as PYTHONPATH)
-h : print this help message and exit (also --help)
-i : inspect interactively after running script; forces a prompt even
if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-I : isolate Python from the user’s environment (implies -E and -s)
-m mod : run library module as a script (terminates option list)
-O : remove assert and debug-dependent statements; add .opt-1 before

import和from…import

在 python 用 import 或者 from…import 来导入相应的模块。
将整个模块(sys)导入,格式为: import sys
从某个模块中导入某个函数,格式为: from sys import path
从某个模块中导入多个函数,格式为: from sys import path,argv
例:

import sys
print ('命令行参数为:')
for i in sys.argv:
print (i)
print ('\n python 路径为',sys.path)

from sys import argv,path  #  导入特定的成员
print('path:',path) # 因为已经导入path成员,所以此处引用时不需要加sys.

变量命名规则

第一个字符必须是字母表中字母或下划线 _ 。
标识符的其他的部分由字母、数字和下划线组成。
标识符对大小写敏感。
在 Python 3 中,可以用中文作为变量名,非 ASCII 标识符也是允许的了。

输入和输出

在python中,输入使用 input来进行输入
input('请输入一个值') #如果不输入,程序将会一直在这里等待。
将输入的值当作变量保存下来
a = input("请给a赋予一个值")
使用输出 print 将a的值输出出来
print(a)
不换行输出
print(a,end="")
print(a)
可见两次输出在同一行

python保留字

在命令行输入python,进入python的交互模式
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’]
可见python保留字有这些。

注释

单行注释:使用 # 开头,例如:
#第一个注释
print("I Love You") # 第二个注释

多行注释 可以使用多个 # 、’’’ 、 “”" 三种方式来注释
#注释1
#注释2
‘’’
注释3
注释4
‘’’
“”"
注释5
注释6
“”"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值