摘要: 把参数 str 所指向的字符串转换为一个整数(类型为 int 型) int atoi(const char *str) 把参数 str 所指向的字符串转换为一个浮点数(类型为 double 型) double atof(const char *str) 阅读全文
posted @ 2024-05-12 22:52 jason8826 阅读(4) 评论(0) 推荐(0) 编辑
摘要: import os # __file__ print("文件绝对路径(含文件名)",__file__) # os.getcwd() print("获取绝对路径(不含文件名)",os.getcwd()) # os.path.abspath(path) print("获取相对路径的绝对路径",os.pa 阅读全文
posted @ 2024-05-10 00:27 jason8826 阅读(3) 评论(0) 推荐(0) 编辑
摘要: # 导入模块 # 格式1:import 模块名1 [as 别名1], 模块名2 [as 别名2]... import sys print("使用模块的成员时,必须添加模块名作为前缀",sys.argv[0]) # 格式2:from 模块名 import 成员名1 [as 别名1],成员名2 [as 阅读全文
posted @ 2024-05-10 00:27 jason8826 阅读(1) 评论(0) 推荐(0) 编辑
摘要: try: a = int(input("输入被除数:")) b = int(input("输入除数:")) c = a / b print("您输入的两个数相除的结果是:", c ) except (ValueError, ArithmeticError): print("程序发生了数字格式异常、算 阅读全文
posted @ 2024-05-10 00:26 jason8826 阅读(1) 评论(0) 推荐(0) 编辑
摘要: # __new__()方法 class Foo(): def __new__(cls,a): print("__new__():",a) instance = super().__new__(cls) # __new__是传入类cls,返回一个实例对象 return instance def __i 阅读全文
posted @ 2024-05-10 00:26 jason8826 阅读(3) 评论(0) 推荐(0) 编辑
摘要: # __init__() 构造方法(或构造函数) # 构造函数可以包含多个参数,但必须包含一个名为self的参数,且必须作为第一个参数 # 构造函数可以手动添加,如果不添加,python也会为类添加一个仅包含self参数的构造方法 class Demo: num1 = '11' num2 = '22 阅读全文
posted @ 2024-05-10 00:25 jason8826 阅读(1) 评论(0) 推荐(0) 编辑
摘要: # python函数 def fun(): return 1,"abcd",2>1 print(fun()) print(type(fun())) print(fun()[1]) # 值传递和引用(地址)传递 # 值传递:适用于实参类型为不可变类型(字符串、数字、元组) # 引用(地址)传递:适用于 阅读全文
posted @ 2024-05-10 00:25 jason8826 阅读(4) 评论(0) 推荐(0) 编辑
摘要: # 条件真假情况如下: # 布尔类型:True为真,False为假 # 对于数字:0或0.0当作假,其它为真 # 对于其它类型,对象为空时为假,其它情况为真,比如:""空字符串、[]空列表、()空元组、{}空字典、None空值。 # pass语句,让解释器跳过此处,什么都不做 a = 10 if 1 阅读全文
posted @ 2024-05-10 00:24 jason8826 阅读(2) 评论(0) 推荐(0) 编辑
摘要: # 字符串拼接 print("11"+"22") # str()和repr()的区别 str1 = "123456" s_str = str(str1) s_repr = repr(str1) print("str: ", s_str) # str()保留了字符串最原始的样子 print("repr 阅读全文
posted @ 2024-05-10 00:23 jason8826 阅读(3) 评论(0) 推荐(0) 编辑
摘要: # 切片操作会生成一个新的序列(而不是提取原先序列的元素) # 创建空列表 list1 = [] # 或 list1 = list() print(list1) # 列表添加元素 # l.append(x) 相当于l[len(l):] = [x] list1.append("12345") prin 阅读全文
posted @ 2024-05-10 00:23 jason8826 阅读(2) 评论(0) 推荐(0) 编辑