python
来源:互联网 发布:帝国cms好用吗 编辑:程序博客网 时间:2024/06/10 02:11
python
#!/usr/bin/python
#coding:utf -8
****非常总要
ASCII 1字节=8bit(8个0101) 2^8-1=255
unicode:2字节=16bit, 2^16-165535 a-字节 你-2字节
utf-8:英文一个字节存储,其他3个字节存储
GB2312:
python解释器
Cpython;
ipython可补齐 是在c上,加强交互式功能
pypy;
jpython
ironpython.net
数值类型
1, 1.0 2e8 2e-8 “hello” , 111111L 布尔类型 (true fasle)
附属类型 x+yj
内置方法:cmp比较.str整形,type查看类型 int向下取整 bool取布尔值 float转为浮点型
ads 绝对值
pow (2,3) 2的3次方
round 四舍五入
divmod 取商和余
coerce 两个数据类型转为同一种
complex(1,3)=1+3j 将数字转化为复数
I/0 输入
input 只接受数值类型
raw_input 接受字符串类型的数据
I/O:
input:
"""
# print "hello"
# 1. input接收数值类型数据:
#year = input("输入判断年份:")
#print type(year)
#print (year%4==0 and year%100!=0) or year%400==0
# 2. raw_input接收字符串类型的数据:
#username = raw_input("用户名:")
#password = raw_input("密码:")
#
#print "username:%s password:%s" %(username, password)
#print "用户名是:", username
#print "密码是:", password
# 3. 输出print
#print "hello world"
#print """
#
#***************************************************************************
#*********************************用户管理系统******************************
#***************************************************************************
#
# 1. 新建用户
# 2. 删除用户
# 3. 登录
#
#"""
#print "1. %s 2.%s" %("java", "python")
#print """
#***************************************************************
#***************************************************************
#
# 1. %s
#
# 2. %s
#
#
#""" %("java", "python")
score1 = input("科目1:")
score2 = input("科目2:")
score3 = input("科目3:")
print (score1 + score2 + score3)/3
输出
三个双因号为括起来输出
格式化输出
if语句
满足表达式语句
if
else: 不满足表达式执行语句
age = input("Age:")
if age > 18:
print "成年"
else:
print "未成年"
"""
if语句的格式:
if 表达式:
满足表达式执行的语句.....
if 表达式:
满足表达式执行的语句.....
else:
不满足表达式执行的语句.....
if 表达式:
满足表达式执行的语句1.....
elif 表达式:
满足表达式执行的语句2.....
elif 表达式:
满足表达式执行的语句3.....
else:
不满足表达式执行的语句.....
三目运算符:
python不支持: a>b?a:b
python支持: a if a>b else b
"""
# 1. if和if...else
#age = input("Age:")
#if age > 18:
# print "成年"
#elif 10<age<18:
# print "boy or girl"
#else:
# print "baby"
#
#2. if包含多重条件表达式
#warn = "敌军来袭"
#if warn:
# print "Warning......"
#else:
# print "一切顺利!"
#warn = ""
#disk_uasge = 78
#
#if warn or disk_uage > 80:
# print "服务器急需维护...."
#else:
# print "一切顺利!"
#3. 三目运算符的实现
num1 = input()
num2 = input()
max = num1 if num1>num2 else num2
print max
#if num1>num2:
# print num1
#else:
# print num2
"""
while循环的语法:
while 表达式:
满足表达式执行的语句
while 表达式:
满足表达式执行的语句
else:
不满足表达式执行的语句
# 死循环/无限循环
while True:
print "hello"
for, break, continue, pass
"""
count = 1
while count < 10:
print count
count += 1
exit()
"""
1. 用户名和密码系统给定;
2. 用户登录时,输入用户名和密码,判断是否登录成功;
增强要求:
1. 用户登录有三次机会,超过3次还未成功,报错;
2. 如果用户名密码正确,显示登录成功,退出程序;(exit())
"""
trycount = 0
while trycount<3:
inname = raw_input("name:")
inpasswd = raw_input("password:")
if inname=="root" and inpasswd=="westos":
print "登录成功!!"
exit()
else:
print "登录失败!!"
trycount += 1
else:
print "超过三次"
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- python
- Python
- @Param注解的用法解析
- AndroidStudio生成JniLibs目录
- 【iOS笔记-2】iOS MVP总结
- c#利用SWIG调用c++dll学习总结
- Leetcode 241. Different Ways to Add Parentheses
- python
- ASP Cookie
- Mybatis自动生成key值(selectKey和useGeneratedKeys)
- 朴素贝叶斯算法--机器学习
- 刚装 Linux 的IP设置
- css背景铺满
- win10任务栏开始菜单等系统图标点击无反应的解决方法
- 水仙花数
- C/S B/S架构区别