Python小白学习之路之数据类型,运算符and输入输出
# Author xyy # Time: 2022/1/10 # Topic This section focuses on the basics of Python, including the use of variables and data types and operators """ var(变量) + logic(逻辑) ==> Python interpreter(解释器) ====>the function of software """ #Definition and use of variables #we do not need to define the type import keyword a = 1 print(a) """ Basics of data types: num: int、long(python3 cancel)、float、complex、bool Advanced data types: dict tuple str list """ print(type(a)) a = (2,3) #tuple print(type(a)) a = [2,3] #list print(type(a)) a = 2j+1 #complex print(type(a)) a = True #bool print(type(a)) a = 1.3 #float print(type(a)) a={2:3} #dict print(type(a)) a=1235456424543278777877 #int py3 no have long print(type(a)) """ keyword:(关键字) ['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'] """ print(keyword.kwlist) a = 3 b = 6 print(a+a,a*a,a**a,b/a,a%b,b-a,b//a) #logic operators: and or not (与、或、非)
运行结果:

Python的基本数据类型为:
int、long(python3 被取消)、float、complex、bool
复杂数据类型
dict、tuple、str、list
# Author xyy # Time: 2022/1/10 # Topic: Input and Output #Output name = "lihua" print("My name is",name) print("My name is %s"%(name)) """ practice: """ qq = 66666666 telephone = 1545424554 address = "白云岗96号" print("======================") print("name:",name) print("QQ:",qq) print("tele:",telephone) print("地址:",address) print("======================") """ format output """ print("name:{}\nqq:{}".format(" "+name,qq)) #input a = input("Please input your name:") print(a) b = int(input("please input your age:")) print(type(b))
运行结果:

注意:type(),可以查看相关变量的类型
可以看出Output有这几种方法:
print("My name is",name)
print("My name is %s"%(name))
print("name:{}\nqq:{}".format(" "+name,qq))

浙公网安备 33010602011771号