回归
#输出函数 print() 展示信息 end = ‘\n’ 换行
#ctrl + f5
#单引号 引号表示的数据 单引号 双引号 三引号都是表示字符串
#end =后边为字符串
#print(‘hello world’,end = ‘’)
#print(‘hello python’)
#print(‘hello world’,end = ‘**’)
#print(‘hello python’,end = ‘**’)
#print(type(456))
#print(type(‘hello’))
#输入函数 input() python 和用户最基本的交互
#name = input(“请输入您的名字”)
#print(“name:” + name)
#print(type(name))#得到input()返回的数据类型
#print(type(“python”))
变量
#变量 杯子 水
#p1 = ‘水’
#print(‘水’)
#print(p1)
#变量命名规则
#变量名可以是字母数字下划线组成,但是数字不能开头
#见名知义
#变量名可以用中文 但是不建议用
#变量名区分大小写
#name = ‘haha’
#p1 = ‘haha’
#_p = ‘hahhha’
#6a = ‘python’
#print(6a)
#你好 = ‘hello’
#print(你好)
#赋值操作 name = ‘beidou’
#name 是变脸 接收值
#= 后边的表示值
#‘beidou’
p1 = 16
p1 = 15
print(p1)
每一个数字对应一个id,p1里存储一个id值,用id值找数字
id = 16的不用就可以删除掉
关键字(不是黑色的)不能做变量名,例如id
>>> id(15)
2344576117488
>>> id = 999
>>> id(15)
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
id(15)
TypeError: 'int' object is not callable
import keyword#导入模块
print(keyword.kwlist)#查看关键字
[‘False’, ‘None’, ‘True’, ‘peg_parser’, ‘and’, ‘as’, ‘assert’, ‘async’, ‘await’, ‘break’, ‘class’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘finally’, ‘for’, ‘from’, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ‘nonlocal’, ‘not’, ‘or’, ‘pass’, ‘raise’, ‘return’, ‘try’, ‘while’, ‘with’, ‘yield’]
内置函数type、print、int也不能作变量名
内置函数 紫色
关键字 黄色
数据类型
整型int() 浮点型float() 布尔型bool() False 0 True 1
type(12.4)
<class ‘float’>
print(False + 1)
1
print(True + 1)
2
除法得到浮点数
字符串
单引号 双引号 三引号(可以换行,结果也换行)
单引号嵌套双引号
字符串只有 + 和 *运算
print(‘hello’ + ‘python’)
print(‘hello’ * 3)
#'%s' 格式化方法 完型天空
name = 'smile'
age = 18
print('%s is a beauty,and she is %s years old'%(name,age) )
smile is a beauty,and she is 18 years old
#format格式化方法
print("{}大美女非常好看,而且今年只有{}岁".format(name,age))
smile大美女非常好看,而且今年只有18岁
print("{1}大美女非常好看,而且今年只有{0}岁".format(name,age))
18大美女非常好看,而且今年只有smile岁
print('****'.join(['hello','python','!']))
结果:hello****python****!
注意join只能用字符串,不能加数字
#类型转换 int() str() float() bool()
var = 123
print(type(var))
作业一:
作业二、三: