Python入门系列教程(一)基础
2016-07-03 13:51
901 查看
基础知识
1.变量及类型2.换行\n
3.输入
password = raw_input("请输入密码:") print '您刚刚输入的密码是:', password
4.格式化输出
a="hello" print('输出%s'%a)
5.ctrl+/注释或者是取消注释
6.sleep
import time time.sleep(2)
7.类型转换
int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换为一个长整数 float(x ) 将x转换到一个浮点数 complex(real [,imag ]) 创建一个复数 str(x ) 将对象 x 转换为字符串 repr(x ) 将对象 x 转换为表达式字符串 eval(str ) 用来计算在字符串中的有效Python表达式,并返回一个对象 tuple(s ) 将序列 s 转换为一个元组 list(s ) 将序列 s 转换为一个列表 chr(x ) 将一个整数转换为一个字符 unichr(x ) 将一个整数转换为Unicode字符 ord(x ) 将一个字符转换为它的整数值 hex(x ) 将一个整数转换为一个十六进制字符串 oct(x ) 将一个整数转换为一个八进制字符串
8.if语句
score=100 if score>90: print "优秀" print "不够优秀"
9.if-else
score=100 if score>90: print "优秀" else: print "不够优秀"
10.not
if not(score>90 and score<=100): print "不够优秀" else: print "优秀"
11.elif
if score>90 and score<=100: print "优秀" elif score>60 and score<90: print "不够优秀" elif score<60: print "不及格"
12.if套嵌
if score>90 and score<=100: if score==100: print "完美" else: print "优秀" else: print "不够优秀"
13.随机数
import random print random.randint(2,7)
14.while循环
i=1 while i<10: print ("当前是第%d次循环"%(i)) i+=1
15.for循环
name="cnki" for temp in name: print temp
16.break
name="cnki" for temp in name: if temp=='k': break print temp
17.continue
name="cnki" for temp in name: if temp=='k': continue #不执行后面的代码,直接进入下一次循环 print temp
18.支持中文
#encoding=utf-8
相关文章推荐
- Two Sum(python)
- Python 语言及其应用 Chapter_4_Note_5 全局变量和局部变量
- Python学习笔记5:Python数字
- AKS Primality test (python code)
- 基于历史数据查询的爬虫操作
- Python 语言及其应用 Chapter_4_Note_4 装饰器
- Python用文件输入替换stdin,stdout
- python之迭代器
- python文件和目录操作方法大全
- 在 Visual Studio 上更好开发 Python 的六大功能!
- Python机器学习库大全
- Python中fileinput模块使用
- Python flask使用templates 和static文件
- Python flask使用templates 和static文件
- Python学习笔记4:Python对象
- python bottle框架
- Python知识点整理(基础篇)
- Python 语言及其应用 Chapter_4_Note_3 闭包_匿名函数lambda_生成器
- Python之软件管理
- Python学习笔记3:Python基础