1.注释
单行注释 #
多行注释 """ """ 或 ''' '''
 
2.简单输出
print("hello world")
 
3.整数与浮点数
a = 3
b = 4
c = a + b
        #变量没有类型,类型是它数值字符的类型
print(c)
print(type(a))                 #type可以打印出数据类型
print(type(b))
print(type(c)) 
 
4.布尔类型
print(3 > 5)
print(a > c)
 
笔记
#变量名可以认为是标识符
#python中的变量不需要声明,每个变量直接赋值即可,变量在使用前需要赋值才可以
# = 用来给变量赋值
# == 用来作为等号
#python标识符由字母数字下划线组成,且数字不能开头
#长度任意,且标识符不能与关键字相同5.显示查阅python关键字
import keyword
#可以显示出python所有的关键字
print(keyword.kwlist)
 
6.输入与输出
price = input("please input your price:")
print("your price is ", price)
print(type(price))    #input输入的任何东西都会变为字符串
 
price1 = input(“请输入单价:”)
price1 =  int(price1)
print(price1, type(price1))
 
price2 = input("请输入斤数:")
price2 = float(price2)
print(price2, type(price2))
 
name = input("请输入你的名字:")
age = int(input("请输入你的年龄:"))
hight = float(input("请输入你的身高:"))
print(“我的名字是”, name)
print("我的年龄是", age)
print("我的身高是",hight)
 
7.占位符的使用
name = "张三"
age = 12
hight = 175.33
sentence = "我叫%s, 我%d,岁了, 我的身高是%.2fcm"%(name,age,hight)
print(sentence)
 
price = 3.5
sentence = "西红柿的单价为%.1f元/每斤"%price
print(sentence)
 
price = float(input(”请输入单价:"))
sentence = “西红柿的单价为%.1f”%price
print(sentence)
 
#百分号的使用
rate = 12.78
sentence = "百分比为%.2f%%"%rate
print(sentence)
 
num = 10
print("%d%%"%num)
 
8.ord把字符转换成对应的十进制的ASCII的位置
print(ord('0'))    #结果为48
print(ord('9'))   #结果为57
 
#ASCII码对应的符号为,可以用%c来转换
print("%c"%(ord('0') +  9))        #结果为9
print("%c"%(64))                      #结果为@
 
9.
name = input("请输入你的名字:")
age = int(input("请输入你的年龄:"))
hight = float(input("请输入你的身高:"))
sentence = "我叫%是, 我的年龄是%d,我的身高是%.2f"%(name, age, hight)
print(snetence)
 
name = input("please input your name:")
sex = input("please input your sex (man:0, woman:1)")
if sex == 1:
        call = Mr
else:
        call = Miss
age = int(input("%s %s, please input your age:"%(call, name)))
hight = float(input("%s %s,please input your hight:"%(calll,name)))
print("我叫%是,我的年龄是%d,我的身高是%.2f"%(name,age, hight))
 
10. .format的使用
s = "我叫{}, 我的年龄是{} "。format("张三", 18)
print(s)
 
sentence = "我在{0}的上大学,我在上{1}年级, 我的数学分数为{2}, 我的英语分数为{2}".format("邯郸", 4, 90)
print(sentence)
 
#可以改变.format()里面的顺序
sentence = “我的姓名是{name}, 我的年龄是{age}, 我的身高是{hight}”.format(name="bob", hight=178, age=18)
 
#:为一种格式,#表示填充的符号,^ 表示局中,10表示总共的位数
#    *表示填充符,<表示居左,>表示居右,8表示总共位数sentence = "我叫{:#^10}, 年龄为{:*<12}".format("伍六七",19)
 
11.eval的作用是计算python的数值,转换成为能够进行计算的形式
s = '3 + 4'
print(s)          #结果:3+4
print(eval(s)) #结果: 7
 
12.
# //号
print(4//3)
print(4//-3)
#结果为1 -2,结果向下取整
 
#判断偶数的标准 a%2==0

#任何数用10取余都将得到他的个位数 
13.抹零操作
money = 3.4*4
zx_money = int(money)
ys_money = zx_money % 10
fin_money = zx_money - ys_money
print(fin_money)
#结果为10
 
money = 92.22
print(money // 10 * 10)
 
# += -= *= /=
a = 5
a += 6
print(a)

b = 5
b *= 10
print(b)