编译型:
解释型:
print(1+2+3+4+5)
print((1+2+3+4+5)*3/2)
print((((1+2+3+4+5)*3/2)+100)/24)
x = 1+2+3+4+5
y = x*3/2
z = (y + 100) / 24
print(x,y,z)
x8 = 100 # True
b__ = 12 # True
4g = 32 # False
_ = 11 # True
*r = 12 # False
r3t4 = 10 # True
t_ = 66 # True
# 变量的小高级:
age1 = 18
age2 = age1
age3 = age2
age2 = 12
# print(age1,age2,age3) # 18 12 18
x y z 变量:代指一些内容
变量全部由数字,字母下划线任意组合。
不能以数字开头。
不能是python的关键字。
[‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘exec‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘lambda‘, ‘not‘, ‘or‘, ‘pass‘, ‘print‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘, ‘with‘, ‘yield‘]
代指一些复杂过长的数据。
人类接触一些信息会做一些比较精准的划分。数字,汉字,英文......?
比如100, ‘中国‘ ,机器是很傻的你要是不给他区分,他是分辨不出来的。
?我们告诉计算机
?100 ,102 ,就是数字(int), + - * / ....
‘中国‘,‘hello‘ ,文字,:记录信息,描述信息等等。
[1, 2, 3, ‘中国‘] 列表,他能做他相应的一些操作即可。 ?
python的基础数据类型。
int(整型): 1、2、123、.... ?
#+ - * / . 运算
i = 100
i1 = 2
i2 = i*i1
print(i2)
str: 凡是用引号引起来的数据就称之为字符串。 ?
#引号(‘‘ "" ‘‘‘ ‘‘‘ """ """)
# str:
s1 = ‘一二三‘
s2 = "一二三"
s2 = ‘‘‘一二三‘‘‘
# 单双引号可以配合使用
# content = ‘I am jarvis, 18 year old‘
# content = "I‘m jarvis, 18 year old"
# 三引号:换行的字符串
msg = ‘‘‘
一二三,
四五六,
七八九。
‘‘‘
# print(msg)
# str 可以否加减乘除? + *
# str + str 字符串的拼接
s1 = ‘人生苦短‘
s2 = ‘我用python‘
# print(s1 + s2)
# str * int
# s1 = ‘python‘
# print(s1*8)
bool :True False
判断变量指向的是什么数据类型? type()
# bool : True False
# print(2 > 1)
# print(3 < 1)
# print(True)
# print(‘True‘)
# s1 = ‘100‘
# s2 = 100
# print(s1,type(s1))
# print(s2,type(s2))
用户交互input
# input: 出来的全部都是字符串类型。
username = input(‘请输入用户名:‘)
password = input(‘请输入密码:‘)
print(username,type(username))
print(password,type(password))
基本结构:
if 条件:
结果
# C: if{条件}{结果}
单独if
print(111)
if 2 < 1:
print(666)
print(333)
print(222)
if else 二选一
s1 = ‘100‘
i1 = int(s1)
print(i1,type(l1))
age = input(‘请输入年龄:‘)
if int(age) > 18:
print(‘成年‘)
else:
print(‘未成年‘)
if elif elif .... 多选一
num = int(input(‘猜点数:‘))
if num == 1:
print(‘这是1‘)
elif num == 3:
print(‘这是3‘)
elif num == 2:
print(‘这是2‘)
if elif elif .... else 多选一
num = int(input(‘猜点数:‘))
if num == 1:
print(‘这是1‘)
elif num == 3:
print(‘这是3‘)
elif num == 2:
print(‘这是2‘)
else:
print(‘没猜到‘)
嵌套的if
username = input(‘请输入用户名:‘)
password = input(‘请输入密码:‘)
code = ‘qwer‘
your_code = input(‘请输入验证码:‘)
if your_code == code:
if username == ‘taibai‘ and password == ‘123‘:
print(‘登录成功‘)
else:
print(‘账号或者密码错误‘)
else:
print(‘验证码错误‘)
原文:https://www.cnblogs.com/rgz-blog/p/12685218.html