Python基础入门(变量)

#变量
counter = 100
miles = 100.0
name = "arron"
#id() id is var address
#type() is the type of var
print(counter,"it`s type is ",type(counter),"and id is ",id(counter))
print(miles,"it`s type is ",type(miles),"and id is ",id(miles))
print(name,"it`s type is ",type(name),"and id is ",id(name))
​
#delette the var
del counter
​
100 it`s type is  <class 'int'> and id is  494734928
100.0 it`s type is  <class 'float'> and id is  71011808
arron it`s type is  <class 'str'> and id is  80531560
In [13]:

#算术运算
a,b,c = 10,20,30
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a//b)
print(a%b)
print(a**b)
30
-10
200
0.5
0
10
100000000000000000000
In [17]:

#比较运算符
print(a == b)
print(a!=b)
print(a>b)
print(a<b)
print(a>=b)
print(a<=b)
False
True
False
True
False
True
In [24]:

#逻辑运算符
print(True and False)
print(True and True)
print(False and False)
print(True or False)
print(True or True)
print(False or False)
print(not False)
print(not True)
print(False and False)
print(True == 1)
print(False ==0)
False
True
False
True
True
False
True
False
False
True
True
In [27]:

#成员运算符
l = [1,2,3,4,5,6]
a,b = 1,10
#l必须是一个可迭代对象
print(a in l)
print(b not in l)
#range(10) 0-9
print(a in range(10))
print(b in range(10))
True
True
True
False
In [31]:

#注释用来说明代码,但是#不只是注释,还代表这某些文件的特殊格式,如脚本开头
''' 
""" """和''' '''用于多行注释
'''
"""
函数的定义
def fun(parameters):
    print(parameters)
​
"""
def fun(name):
    print("My name is ",name)
fun("arron")
My name is  arron
 

猜你喜欢

转载自blog.csdn.net/weixin_38452632/article/details/83542354