首页 技术 正文
技术 2022年11月8日
0 收藏 909 点赞 1,304 浏览 3584 个字

1

、pycharm的使用

python0301

python0301

python0301

python0301

python0301

python0301

python0301

python0301

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('牧马城市')

python0301

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

python0301

# 从 1 ~ 100 利用while循环

python0301

# 计数器的概念# 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)

python0301

# 打印 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

python0301

# 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)

python0301

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

python0301

# 固定搭配: 循环只要被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

python0301

# 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                ?

% 真正操作步骤:

  1. 用第一个数除以第二个数,得到最相近的两个商。取最小的数。
  2. 用第一个数减去第二个数和第一步的到的数的乘积。

赋值运算符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 :

语句体]

执行顺序:

  1. 初始化部分:一般是用来定义循环变量或新赋值
  2. 判断循环条件:

真:

执行循环体语句

是否执行了break语句

执行了:跳过else

没执行:当while正常执行完后,执行else

回到第二步条件判断

假:执行else

break:停止:直接停止当前的循环,不论还剩下多少次循环。

continue:跳过当前循环后面的语句,直接执行下一轮循环。

gbk:简体中文。一个中文编码成两个字节。

utf-8:中文一般是3个字节。

针对英文,始终是一个字节。

ascii –》 gbk

ascii–》 utf8



    					
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,486
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,126
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,287