Python基础语法

编码

# -*- coding: cp-1252 -*-
# -*- coding: utf-8 -*-

交互式编程

-Windows
C:\Users\cy>python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bi
t (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
-Linux
[root@izwz91cugo68lt8hfj4j0uz ~]# python
Python 2.7.5 (default, Aug  4 2017, 00:39:18) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

脚本式编程

[root@izwz91cugo68lt8hfj4j0uz ~]# python test.py 
Hello,World!
[root@izwz91cugo68lt8hfj4j0uz ~]# ./test.py 
Hello,World!
[root@izwz91cugo68lt8hfj4j0uz ~]# 

Python命名规范

文件名部分:
    大小写字母、数字、下划线
    不用数字开头
    名称有意义
    避免使用python保留字和关键字
文件后缀:
    .py
    .pyw

Python关键字

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

缩进

注释

-行注释
print("Hello,World!") #打印Hello,World!
-块注释
"""
多行注释
随便写点
"""

输出与输入

-print()

默认换行

print("这是")
print("在不同行")

使用end=”“使输出在同一行

print("这是",end="")
print("在同一行")
-input()
u_name=input("Please input your name:")
print("Hi %s" % u_uname)
print("Hi {0}".format(u_name))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值