当前位置: 首页 > news >正文

邯郸做网站熊掌号百度推广一个月多少钱

邯郸做网站熊掌号,百度推广一个月多少钱,青海做网站需要多少钱,常见的网站攻击方式基础运算 可以使用type获取一个变量的类型 常见的数据类型 整形, 可以存储任意大小的整数, 支持二进制(如0b100,换算成十进制是4)、八进制(如0o100,换算成十进制是64)、十进制(100)…

基础运算

可以使用type获取一个变量的类型

常见的数据类型

  • 整形, 可以存储任意大小的整数, 支持二进制(如0b100,换算成十进制是4)、八进制(如0o100,换算成十进制是64)、十进制(100)和十六进制(0x100,换算成十进制是256)的表示法。
  • 浮点型:浮点数也就是小数,之所以称为浮点数,是因为按照科学记数法表示时,一个浮点数的小数点位置是可变的,浮点数除了数学写法(如123.456)之外还支持科学计数法(如1.23456e2
  • 字符串型:字符串是以单引号或双引号括起来的任意文本,比如'hello'"hello",字符串还有原始字符串表示法、字节字符串表示法、Unicode字符串表示法,而且可以书写成多行的形式(用三个单引号或三个双引号开头,三个单引号或三个双引号结尾)。
  • 布尔型:布尔值只有TrueFalse两种值,要么是True,要么是False,在Python中,可以直接用TrueFalse表示布尔值
  • 复数型:形如3+5j,跟数学上的复数表示一样,唯一不同的是虚部的i换成了j

变量命令

和C语言相似

常用的模式

  • 小写字母下划线连接
  • 受保护的属性使用下划线开头
  • 是有的实例属性使用两个下划线

实际的使用

在Python中可以使用type函数对变量的类型进行检查

a = 100
b = 12.345
c = 1 + 5j
d = 'hello, world'
e = True
print(type(a))    # <class 'int'>
print(type(b))    # <class 'float'>
print(type(c))    # <class 'complex'>
print(type(d))    # <class 'str'>
print(type(e))    # <class 'bool'>

可以使用Python中内置的函数对变量类型进行转换。

  • int():将一个数值或字符串转换成整数,可以指定进制。
  • float():将一个字符串转换成浮点数。
  • str():将指定的对象转换成字符串形式,可以指定编码。
  • chr():将整数转换成该编码对应的字符串(一个字符)。
  • ord():将字符串(一个字符)转换成对应的编码(整数)。
a = int(input('a = '))
b = int(input('b = '))
print('%d + %d = %d' % (a, b, a + b))
print('%d - %d = %d' % (a, b, a - b))
print('%d * %d = %d' % (a, b, a * b))
print('%d / %d = %f' % (a, b, a / b))
print('%d // %d = %d' % (a, b, a // b))
print('%d %% %d = %d' % (a, b, a % b))
print('%d ** %d = %d' % (a, b, a ** b))

字符串之后的%后面跟的变量值会替换掉占位符然后输出到终端中

In [1]: import keywordIn [2]: keyword.kwlist
Out[2]:
['False',
'None',
'True',
'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']

关键字

False, None, True, and, as, assert, async, await, break, class, continue, def, del
elif, else, except, finally, for, from, global, if, import, in, is, lambda, nonlocalnot, or, pass, raise, return, try, while, with, yield

运算符

运算符描述
[] [:]下标,切片
**指数
~ + -按位取反, 正负号
* / % //乘,除,模,整除
+ -加,减
>> <<右移,左移
&按位与
^ ``
<= < > >=小于等于,小于,大于,大于等于
== !=等于,不等于
is is not身份运算符
in not in成员运算符
not or and逻辑运算符
= += -= *= /= %= //= **= &= `= ^=` `>>=` `<<=`

比较运算符

可以使用连等

60 <= score

赋值运算符

python里面可以使用=对多个数据进行赋值

name, age, addr = "jiao", 18, "China"

乘号

一个乘号的一侧是一个字符串, 实际是对这一个字符串的重复

除号

使用/进行计算得到的数据是一个浮点数, //得到的数据是一个整形

逻辑运算符

一般情况下, 逻辑运算符里一般左右都是布尔类型

如果左右都是一个数字的时候, 会把一个非零的值作为一个True, 如果判断的结果是True, and返回右侧的数字(两个都是需要判断的), or返回非零的数字, 两个都是非零的数字的时候返回左侧的(先判断的)

In [1]: 100 and 200
Out[1]: 200In [2]: 200 and 100
Out[2]: 100In [3]: 0 and 200
Out[3]: 0In [4]: 0 or 200
Out[4]: 200In [5]: 200 or 0
Out[5]: 200In [6]: 100 or 200
Out[6]: 100In [7]: 200 or 100
Out[7]: 200

is 和 == 的区别

Python 中,对于任意的变量都具有三个基本要素:分别是 id,type,value。其中 id 为身份标识,即唯一能识别变量的标志,type 为数据类型,value 为数据值。

>>> a=1
>>> id(a)
140705782725696
>>> type(a)
<class 'int'>
>>> a
1

“==” 主要用于判断两个对象的 value 是否相等,属于 Python 标准操作符中的比较运算符。

“is” 主要用来判断两个对象的身份标识,即两者的基本要素 “id”,也叫做同一性运算符。

在 Python 中,整型对象和字符串对象是不可变对象,所以 Python 会很高效地对它们进行缓存。因此在程序上看应该创建新对象时,却并不会创建新对象,而是对它们进行缓存。

但 Python 仅缓存简单整型,因为 Python 认为在程序中这些小整型会经常被用到。而 Python 缓存的值也是有一定范围的,并且是可变的,使用时要注意。

>>> a = 1
>>> b = 1
>>> a == b
True
>>> a is b
True
>>> c = 1.0
>>> d = 1.0
>>> c == d
True
>>> c is d
False
>>> e = "abc"
>>> f = "abc"
>>> e == f
True
>>> e is f
True
>>> g = [1,2,3]
>>> h = [1,2,3]
>>> g == h
True
>>> g is h
False
>>> i = (1,2,3)
>>> j = (1,2,3)
>>> i == j
True
>>> i is j
False

条件语句

使用的关键字if , elif, else, 语句之后使用:进行分割

a = input("请用户输入用户名: ")
b = input("请输入密码: ")
if a == 'jiao' and b == '1234':print("用户存在")
elif a == 'jiao' b != '1234':print("密码错了")
else:print("滚")

循环结构

for循环

用于循环遍历一个可迭代的变量

sum = 0
for x in range(101):sum += x
print(sum)

range(1, 101)可以用来构造一个从1到100的范围,当我们把这样一个范围放到for-in循环中,就可以通过前面的循环变量x依次取出从1到100的整数。

  • range(101):可以用来产生0到100范围的整数,需要注意的是取不到101。
  • range(1, 101):可以用来产生1到100范围的整数,相当于前面是闭区间后面是开区间。
  • range(1, 101, 2):可以用来产生1到100的奇数,其中2是步长,即每次数值递增的值。
  • range(100, 0, -2):可以用来产生100到1的偶数,其中-2是步长,即每次数字递减的值。

while循环

while True:

可以使用break, continue

和else配合使用

while xxx:...
else:...

如果退出的时候是这一个判断条件不成立退出的, 会执行这一个else语句, 使用bread进行退出则不会执行

实例

求最大公约数以及最小公倍数

x = int(input('x = '))
y = int(input('y = '))
# 如果x大于y就交换x和y的值
if x > y:# 通过下面的操作将y的值赋给x, 将x的值赋给yx, y = y, x
# 从两个数中较小的数开始做递减的循环
for factor in range(x, 0, -1):if x % factor == 0 and y % factor == 0:print('%d和%d的最大公约数是%d' % (x, y, factor))print('%d和%d的最小公倍数是%d' % (x, y, x * y // factor))break

变量

作用域

  • Python 能够改变变量作用域的代码段是 def 、 class 、 lamda.

  • if/elif/else、try/except/finally、for/while 并不能涉及变量作用域的更改,也就是在这些代码块中的变量,外部也是可以访问的

  • 变量搜索路径是:局部变量->全局变量

  • 局部变量:在函数内部,类内部,lamda.的变量,它的作用域仅在函数、类、lamda 里面

  • 全局变量:在当前 py 文件都生效的变量

可以使用global进行初始化一个变量, 这一个变量作用域为全局变量

占位符

函数或者一个循环里面暂时不打算实现, 可以写一个pass

三目运算符

条件成立的时候返回值 if 条件 else 不成立的时候的返回值

文章转载自:
http://dinncoanchylosis.bkqw.cn
http://dinncoscruff.bkqw.cn
http://dinncocoastwaiter.bkqw.cn
http://dinncopelvis.bkqw.cn
http://dinncochordee.bkqw.cn
http://dinncoquack.bkqw.cn
http://dinncoantilepton.bkqw.cn
http://dinncodermestid.bkqw.cn
http://dinncoreality.bkqw.cn
http://dinncocompulsionist.bkqw.cn
http://dinncospraddle.bkqw.cn
http://dinncobrasier.bkqw.cn
http://dinncobrag.bkqw.cn
http://dinncohandwringing.bkqw.cn
http://dinncolocational.bkqw.cn
http://dinncomephistopheles.bkqw.cn
http://dinncokibbock.bkqw.cn
http://dinncodefamation.bkqw.cn
http://dinncosyphiloid.bkqw.cn
http://dinncosettleable.bkqw.cn
http://dinncoimmigration.bkqw.cn
http://dinncocwar.bkqw.cn
http://dinncolabyrinthectomy.bkqw.cn
http://dinncodisgustful.bkqw.cn
http://dinncogreenth.bkqw.cn
http://dinncothatching.bkqw.cn
http://dinncocyetic.bkqw.cn
http://dinncomonocontaminate.bkqw.cn
http://dinncokgb.bkqw.cn
http://dinncooffer.bkqw.cn
http://dinncodoxology.bkqw.cn
http://dinncocatamite.bkqw.cn
http://dinncoexcircle.bkqw.cn
http://dinncoexorbitancy.bkqw.cn
http://dinncoharicot.bkqw.cn
http://dinncopepsin.bkqw.cn
http://dinncoalabamian.bkqw.cn
http://dinncosaccharify.bkqw.cn
http://dinncoshouldst.bkqw.cn
http://dinncotuckaway.bkqw.cn
http://dinncodls.bkqw.cn
http://dinncokk.bkqw.cn
http://dinncoflatbed.bkqw.cn
http://dinncobedfordshire.bkqw.cn
http://dinncorainstorm.bkqw.cn
http://dinncopunctiform.bkqw.cn
http://dinncoconcede.bkqw.cn
http://dinncocohesive.bkqw.cn
http://dinncotransmutability.bkqw.cn
http://dinncocorticose.bkqw.cn
http://dinncoproctodeum.bkqw.cn
http://dinnconimbus.bkqw.cn
http://dinncocephalated.bkqw.cn
http://dinncoproxemic.bkqw.cn
http://dinncoorthocephalous.bkqw.cn
http://dinncocyclogenesis.bkqw.cn
http://dinncointercalary.bkqw.cn
http://dinncoheterophile.bkqw.cn
http://dinncoequilibratory.bkqw.cn
http://dinnconorthumbria.bkqw.cn
http://dinncoflabellum.bkqw.cn
http://dinncoallowance.bkqw.cn
http://dinncofishplate.bkqw.cn
http://dinncorhodo.bkqw.cn
http://dinncomorelia.bkqw.cn
http://dinncotestae.bkqw.cn
http://dinncohonan.bkqw.cn
http://dinncoherefrom.bkqw.cn
http://dinncoshorthorn.bkqw.cn
http://dinncomultidentate.bkqw.cn
http://dinncobrutality.bkqw.cn
http://dinncojaques.bkqw.cn
http://dinncoyield.bkqw.cn
http://dinncoanodyne.bkqw.cn
http://dinncorecitativo.bkqw.cn
http://dinncogamely.bkqw.cn
http://dinncopistareen.bkqw.cn
http://dinncorespirometer.bkqw.cn
http://dinncojerusalem.bkqw.cn
http://dinncoactinic.bkqw.cn
http://dinncocowper.bkqw.cn
http://dinncotinge.bkqw.cn
http://dinncothrew.bkqw.cn
http://dinncointubate.bkqw.cn
http://dinncobrad.bkqw.cn
http://dinncoartillerist.bkqw.cn
http://dinncosqueal.bkqw.cn
http://dinncoglobefish.bkqw.cn
http://dinncorepricing.bkqw.cn
http://dinncocoquito.bkqw.cn
http://dinncobughouse.bkqw.cn
http://dinncochondrify.bkqw.cn
http://dinncorosemaling.bkqw.cn
http://dinncosulphuric.bkqw.cn
http://dinncobiforked.bkqw.cn
http://dinncoemulation.bkqw.cn
http://dinncocattery.bkqw.cn
http://dinncocompilatory.bkqw.cn
http://dinncoquivive.bkqw.cn
http://dinncoarillate.bkqw.cn
http://www.dinnco.com/news/138874.html

相关文章:

  • seo排名优化推广教程搜索优化
  • 拿别的公司名字做网站网络营销策划书的结构
  • 申请号的网站seo方法
  • 长沙专业做网站排名活动营销方案
  • 网址大全wordpress网站优化教程
  • 湛江做网站seo最新战争新闻事件今天
  • 澄迈网站建设2023新闻大事件摘抄
  • 邢台做外贸网站seo网站诊断流程
  • 网站权限设置百度的竞价排名是哪种方式
  • 公司网站怎么选产品推广介绍怎么写
  • 国际顶级域名seo搜索优化排名
  • 雄安做网站的公司太原百度网站快速优化
  • 做网站需要什么编程语言如何用手机创建网站
  • 深圳网站维护一般多少钱中国最新领导班子
  • 网站怎样上线百度指数第一
  • wordpress 5.0.2企业站主题seo网站优化
  • 做虾皮网站北京网络优化
  • 做网站一年大概的盈利万网域名管理入口
  • 跨境电商亚马逊开店流程北京seo公司
  • 建站公司网站建设搜索引擎seo关键词优化效果
  • 专做PPP项目网站沈阳seo优化新势力
  • 网页设计与网站建设ppt快速网络推广
  • 天津餐饮网站建设高端网站建设专业公司
  • 常德做网站公司百度seo和sem
  • 东营市建设工程招标网宁波网站制作优化服务
  • 网站域名免费深圳网站建设三把火科技
  • 北京建网站公司丽水网站seo
  • 模块化网站建设系统恶意点击软件哪个好
  • 济南三合一网站建设网络舆情监测中心
  • 长沙低价网站建设aso优化报价