(一)Python概述
- Python概述
- Python数值对象
- 三大流程控制
Python概述
Python 是一门优雅而健壮的编程语言,它继承了传统编译语言的强大性和通用性,同时也借鉴了简单脚本和解释语言的易用性。
Python数值对象
1.变量
变量是内存中的一块区域,对象赋值实际上是对象的引用。a=10
变量的命名:变量名由字母,数字,下划线组成,不能以数字开头
(hello=100, hello_world=100)
变量定义时不需要指定类型的,当用变量时,必须要给这个变量赋值。
2.基本数据类型-数值类型
float(浮点值)
complex(复数)
int(有符号整数):-237;0x80
long(长整数)
bool(布尔值)
3.运算符(需要特别注意的)
1)算术运算符:
/: a=5/3 print(a) b=5.0/3 print(b)
输出:1.6666666666666667 1.6666666666
%: a=5%3 print(a) b=5.0%3.0 print(b)
输出:2 2.0
//:a=5//3 print(a) b=5.0//3.0 print(b)
输出:1 1.0
4.I/O操作
输入(input)
- input:python3中接受字符串
- raw_input:python3中删除
- getpass:接受密码,输入的信息不可见(模块)
输出(output)
Exercise1
course1=95
course2=64
course3=79
print(course1)
print(course2)
print(course3)
sumScore=course1+course2+course3
print(sumScore)
avg_score=(course1+course2+course3)/3
print("%.2f" % avg_score)
#取两位小数方法二:avg_score=round(avg_score1,2)
Exercise2
faherenheit=float(input("华氏度为:"))
celsius=("%.2f" % ((faherenheit-32)/1.8))
print(celsius)
三大流程控制
if语句四种语法结构