python之路:进击的小白
2016-05-15 17:05
489 查看
1.hello world
print("hello world")
2.变量定义的规则
变量名只能是 字母、数字或下划线的任意组合
变量名的第一个字符不能是数字
以下关键字不能声明为变量名
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
3.字符编码-*-coding:utf-8-*-
在python2.0版本中,不声明字符编码则不支持中文
python3.0可以不声明默认是 -*-coding:utf-8-*-
4.注释:
单行注释: "#"
多行注释: " ''' "(3个单引号)
5.输入
name_input=input("用户名:")
password_input=input("密码")
密码可以密文(在linux环境中)
6.模块
os模块
sys模块
Tab模块
猜年龄
break跳出本层循环
continue不向下循环从头开始循环
print("hello world")
2.变量定义的规则
变量名只能是 字母、数字或下划线的任意组合
变量名的第一个字符不能是数字
以下关键字不能声明为变量名
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
3.字符编码-*-coding:utf-8-*-
在python2.0版本中,不声明字符编码则不支持中文
python3.0可以不声明默认是 -*-coding:utf-8-*-
4.注释:
单行注释: "#"
多行注释: " ''' "(3个单引号)
5.输入
name_input=input("用户名:")
password_input=input("密码")
密码可以密文(在linux环境中)
#!/usr/bin/env python #-*-coding:utf-8-*- import getpass password_input=getpass.petpass("密码:")
6.模块
os模块
#!/usr/bin/env python # -*- coding: utf-8 -*- import os os.system("df -h") #调用系统命令
sys模块
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys print(sys.argv) #输出 $ python test.py helo world ['test.py', 'helo', 'world'] #把执行脚本时传递的参数获取到了
Tab模块
#!/usr/bin/env python #-*-coding:utf-8-*- num = 20 counter = 0 for i in range(10): if counter<3: guess_num = int(input("输入年龄:")) if guess_num > num: print("猜大了") elif guess_num < num: print("猜小了") else: print("猜对了") break else: couter_confirm = input("还想继续吗?") if couter_confirm == 'y': counter = 0 continue else: print("bay!") break counter +=1
猜年龄
break跳出本层循环
continue不向下循环从头开始循环
相关文章推荐
- Python Tricks(一)—— np.where 与最大最小截断
- python write file
- 简单的python爬虫(爬取百度百科词条)
- 爬取了豆瓣11W+网页,获取了5W+有效书籍信息
- Python 第一课,初接触。
- Python:告别if...else...做真正面向对象的编程
- Python 类和实例
- python实现不可修改的常量
- python-装饰器封装try-exception
- Python XML操作
- python处理文件tab替换成空格
- Python实战_1_第一周_第二节练习项目:爬取商品信息
- Python笔记之入门(基础篇)
- 【opencv+python】图像处理之一、颜色空间RGB,Gray与HSV
- 糗百爬虫V2,可爬图片和段子
- python学习笔记3—流程控制if、for、while
- 初识python(1)
- wxPython & PyQT
- iYMS系统
- Kajiki XML 引擎库