python0301
1
、pycharm的使用








2、格式化输出
# name = input('请输入姓名')# age = input('请输入年龄')# hobby = input('请输入爱好')# msg = '我的姓名是' + name + '我今年' + age + '我的爱好是' + hobby# print(msg)# 字符串的拼接可以制作一个公共字符串模板,让某些位置变成动态的。"""msg = '''------------ info of Alex Li -----------Name : Alex LiAge : 73job : sbbossHobby: laddy_boy------------- end -----------------'''
msg1 = '''------------ info of 杨苏婷 -----------Name : 杨苏婷Age : 18job : student# name = input('请输入姓名:')# age = input('请输入年龄:')# job = input('请输入工作:')# hobby = input('请输入爱好:')# '''# 这样做很麻烦,用格式化输出# s1 = '------------ info of '+ name + ' -----------\n'# s2 = 'Name : ' + name + '\n'# '''# # % 占位符 s:字符串类型 d:数字 i:数字 # r 原形毕露# msg = '''------------ info of %s -----------# Name : %s# Age : %d# job : %s# Hobbie: %s# ------------- end -----------------''' % (name,name,int(age),job,hobby)# print(msg)
# 格式化输出 如果你只是想要表示百分号%,而不是占位符。# msg = '我叫%s,今年%s岁,学习进度为0.5%%' % ('高航', 40)# print(msg)Hobbie: movie------------- end -----------------'''"""
# 1,初识循环# while True:# print('海草')# print('女儿情')# print('二泉映月')# print('牧马城市')

# 如何终止循环'''1,改变条件。2,break3,调用系统命令:quit() exit() (不建议使用)'''
# flag = True# while flag:# print('海草')# print('女儿情')# flag = False# print(111)# print(222)# 四个都打印

# 从 1 ~ 100 利用while循环

# 计数器的概念# count = 1# flag = True# while flag:# print(count)# count = count + 1# if count == 101:# flag = False
结果:1-100循环
# count = 1# while count < 101:# print(count)# count = count + 1
_____________________________________ # count = 1# count = 2# count = 3# print(count)# count = 1# count = count + 1# count = count + 1# print(count) 结果3 3# while break continue# break:循环中遇到break 直接退出循环,# print(111)# while True:# print(222)# print(333)# break# print(555)# print(666)

# 打印 1~100 所有的偶数。# 方法一# count = 2# while count < 101:# print(count)# count = count + 2 # count = 2# while True:# if count % 2 == 0:# print(count)# count = count + 1# if count > 100:# break

# count = 2# while count < 101:# if count % 2 == 0:# print(count)# count = count + 1 # continue# 结束本次循环,继续下一次循环# while True:# if# print(111)# print(222)# continue# print(333)

# 计算 1 + 2 + 3 + 4 + 5 + ...100 结果## s = 0# count = 1# while count < 101:# s = s + count# count = count + 1# print(s)

# 固定搭配: 循环只要被break打断,则就不会执行else的程序。#while else# count = 1# while count < 5:# count = count + 1# print(count)# else:# print(666)
count = 1while count < 5: count = count + 1 print(count) if count == 10: breakelse: print(666) 结果:2345666

# print(2**3)
# 逻辑运算
# 优先级# ()>not>and> or,同一个优先级从左至右一次计算。
# 1,运算符两边全部是比较运算。# print(1 > 2 or 3 < 4 and 1 < 2 or 3 > 7)
# print(1 > 2 or True or 3 > 7)
# print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)# print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 <10)
# 2 ,运算符两边全部是数字。'''x or y if x is True, return x,else y'''# print(1 or 3)# print(2 or 3)# print(10 or 3)# print(0 or 3)# print(-3 or 3)# print(1 and 3)# print(-1 and 3)# print(0 and 3)#int bool# int ---> bool 非0即True# print(bool(-2))# print(bool(2))# print(bool(0))# bool ---> int True 1 Flase 0# print(int(True))
# 面试题:# print(1 and 3 or 4 and 5)
# 第三种,思考题:# print(1 > 2 or 3 and 4 < 5 or 7)
# 成员运算:# s = 'alex 中'# s1 = 'a's = 'alexsb'# print('a' in s)# print('al' in s)# print('ae' in s) # False# print('alex' in s) # False# print('alexsb' in s) # False
# print('a' not in s)# print(2**16)print(2**32)
算数运算符arithmetic operator:
+ - * / %
% : 取余,取模。取的是第一个操作数和第二个操作数除法的余数。整除结果为0.
10 % 3 1
10 % 5 0
10 % -3 -1
10 % -5 ?
-10%3 ?
% 真正操作步骤:
- 用第一个数除以第二个数,得到最相近的两个商。取最小的数。
- 用第一个数减去第二个数和第一步的到的数的乘积。
赋值运算符assignment operator:
基本的赋值运算符:=
扩展的赋值运算符:
+= -= *= /= %=
例如:X += Y -> X = X + Y
比较运算符compare operator:
<= >= == !=
比较运算符的结果始终是布尔类型。
逻辑运算符logic operator:
python中只有三个逻辑运算符:
and or not
逻辑运算符的结果到底是什么类型???
结果取决于两个操作数的类型!!!
针对and操作:第一个操作数如果是可以转成False的话,那么第一个操作数的值,就是整个逻辑表达式的值。
如果第一个操作数可以转成True,第二个操作数的值就是整个表达式的值。
针对or操作:第一个操作数如果是可以转成False的话,第二个操作数的值就是整个表达式的值。
如果第一个操作数可以转成True, 第一个操作数的值,就是整个逻辑表达式的值。
成员运算符:
in not in
while循环:
[初始化部分一般是用来定义循环变量]
while 循环条件:
循环体语句
[循环变量更改部分]
[else :
语句体]
执行顺序:
- 初始化部分:一般是用来定义循环变量或新赋值
- 判断循环条件:
真:
执行循环体语句
是否执行了break语句
执行了:跳过else
没执行:当while正常执行完后,执行else
回到第二步条件判断
假:执行else
break:停止:直接停止当前的循环,不论还剩下多少次循环。
continue:跳过当前循环后面的语句,直接执行下一轮循环。
gbk:简体中文。一个中文编码成两个字节。
utf-8:中文一般是3个字节。
针对英文,始终是一个字节。
ascii –》 gbk
ascii–》 utf8
python0301的更多相关文章
随机推荐
- dump命令详解
1.简介: dump命令用于备份文件系统. dump为备份工具程序,可将目录或整个文件系统备份至指定的设备,或备份成一个大文件. 2.语法: dump [-cnu][-0123456789][-b & ...
- Alfred 3 如何设置默认搜索引擎(以百度搜索为例)
前提条件: Alfred 3 已经安装在MAC中 首先要有破解的Alfred 3 安装在MAC PRO中,然后进入到以下栏目:Features-->web Search-->Add Cus ...
- phpstorm界面不停的indexing,不停的闪烁
选择 File->Invalidate Caches / Restart...->Invalidate and Restart,就行了!
- Exp1 PC平台逆向破解 20165110 石钰
Exp1 PC平台逆向破解 20165110 石钰 一.实践目标 1.实验背景 实践对象是pwn1的Linux可执行文件,该程序的正常该程序正常执行流程是:main调用foo函数(oo函数会简单回显任 ...
- 洛谷P3655 差分数组 树状数组
题目链接:https://www.luogu.org/problemnew/show/P3655 不一定对,仅供参考,不喜勿喷,不喜勿喷. 先copy洛谷P3368 [模板]树状数组 2 题解里面一位 ...
- Android Studio 集成开发工具教学视频
简介 经过2年时间的研发,Google终于正式发布了面向Android开发者的集成开发环境Android Studio 1.2(稳定版).Android Studio是Google开发的一款面向And ...
- JS——按钮点击事件累加注册问题
最近在工作上遇到一个点击事件累加的问题,为元素添加点击事件效果,但是总是效果失败,最后发现点击事件被执行了多次,上网查了一下,下边就是解决这个问题的几种思路 案列引自 踮起脚尖眺望6 $(" ...
- TZOJ 2569 Wooden Fence(凸包求周长)
描述 Did you ever wonder what happens to your money when you deposit them to a bank account? All banks ...
- 11.20 正则表达式 断言(?=exp)
今天看源代码,研究了一下qz写的这个方法: // 添加逗号分隔,返回为字符串 comma: function(length) { ) length = ; var source = ('' + thi ...
- django filter or 多条件查询
功能:django中实现多条件查询 或关系: from django.db.models import Q return qs.filter(Q(notice_to_group__contains=' ...