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                ?

% 真正操作步骤:

  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


												

python0301的更多相关文章

随机推荐

  1. [原创] debian 9.3 搭建seafile企业私有网盘

    [原创] debian 9.3 搭建seafile企业私有网盘 需求是这样的, 个人疲惫于 "成为大伙的文件中转站" ,公司不管大大小小的文件,都要打电话过来“转个xx文件”.“帮 ...

  2. Sping4之依赖注入

    Spring的依赖注入可以是我们不需要去管理bean,网上看到一个回答很精辟: 现在你需要买一把锤子: 1.自己做一把,解释成java就是,调用者创建被调用着,也就是自己去创造一个造锤子的方法,然后自 ...

  3. HTTP 学习心得

    一.什么是HTTP? 超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必须遵守这个标准.设计HTTP最初的目的 ...

  4. Myeclipse运行单个jsp页面

    点击窗口--->打开透视图--->其他 选中Web(WTP Extras) 如果没有这一项勾选 全部显示 应该是会生成一个Server文件夹

  5. 腾讯2019年暑期实习生招聘提前批在线笔试技术研究和数据分析方向t2(python)

    小Q有一叠纸牌,一共有n张,从上往下依次编号为1~n.现在小Q要进行以下重复操作:把位于顶端的牌扔掉,把新的顶端的牌放到这叠牌的底部.小Q会一直操作到只剩下一张牌为止,小Q想知道每次扔掉的牌的编号.[ ...

  6. go语言变量

    变量可以通过变量名访问 Go 语言变量名由字母.数字.下划线组成,其中首个字符不能为数字 声明变量的一般形式是使用 var 关键字: var identifier type 变量声明 1. 指定变量类 ...

  7. code first , Migration

    文章引用至: https://www.cnblogs.com/panchunting/p/entity-framework-code-first-migrations.html 随着业务的增加, 之前 ...

  8. 20164319 刘蕴哲 Exp4:恶意代码分析

    [实验内容] ①系统运行监控 使用如计划任务,每隔一分钟记录自己的电脑有哪些程序在联网,连接的外部IP是哪里.运行一段时间并分析该文件,综述一下分析结果.目标就是找出所有连网的程序,连了哪里,大约干了 ...

  9. windows 下安装redis

    https://github.com/MicrosoftArchive/redis/releases redis 服务安装到系统 redis-server.exe --service-install ...

  10. redis知识点

    为什么使用 ①解决应用服务器的cpu和内存压力 ②减少io的读操作,减轻io的压力 ③关系型数据库的扩展性不强,难以改变表结构 优点: ①nosql数据库没有关联关系,数据结构简单,拓展表比较容易 ② ...