python
tyustli
不抛弃,不放弃
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Python--bin 文件生成 C 语言数组
python 源码import osimport sysimport structdef output_bin(bin_file, fd_file): fd_bin=open(bin_file, 'rb') data=fd_bin.read(4) count=0 while (len(data)==4): temp=struct.unpack("<L", data) if ((count%4)==0):原创 2021-05-21 22:19:01 · 774 阅读 · 0 评论 -
Python-赋值语句后面加逗号
元组元组定义说明元组使用小括号表示,数据元素用逗号(,)隔开赋值语句加逗号赋值语句加逗号起到强制类型转换的作用,转换后的数据类型是元组示例程序a = 123b = 456,print type(a)print type(b),print("\n-----------------")# <type 'int'># <type 'tuple'>c = [123, 456, "tyustli"]d = [123, 456, "tyustli"],print原创 2021-05-21 22:01:14 · 1645 阅读 · 0 评论 -
python-随机生成 C 语言的字符串数组
import randomimport click# using sample : python generate.py generate -l 5 -n 6# {"4QSn8O", "gKND", "Tnr3", "Gkz1ndxg2s", "OgIxM", "AI8esGN", }BASE_STR = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'BASE_NUM = [4, 5, 6, 7, 8, 9, 1原创 2020-12-24 17:48:27 · 256 阅读 · 1 评论 -
C语言-比较字符串是否相等(计时攻击)
C 语言版#include <stdio.h>int util_cmp_const(const void *a, const void *b, const size_t size){ const unsigned char *_a = (const unsigned char *)a; const unsigned char *_b = (const unsigned char *)b; unsigned char result = 0; size_t i原创 2020-12-23 13:32:13 · 528 阅读 · 0 评论 -
python-文件与异常
# 关键字 with 在不再需要访问文件后将其关闭。with open('pi_digits.txt') as file_object: file_read = file_object.read() print(file_read)# 3.1415926# 异常try: print(5 / 0)except ZeroDivisionError: print("you can not divide by zero")...原创 2020-12-14 23:32:02 · 110 阅读 · 0 评论 -
python-类
# 创建 dog 类class Dog(): def __init__(self, name, age): self.name = name self.age = age def sit(self): print(self.name.title() + " is now sitting") def roll_over(self): print(self.name.title() + " rolled over")原创 2020-12-14 23:12:09 · 97 阅读 · 0 评论 -
python-函数
# 定义函数def greet_user(): print("hello")greet_user()# hello#向函数传递信息def greet_user1(name): print("hello " + name.title() + " !")message = "tyustli"greet_user1(message)# hello Tyustli !原创 2020-12-14 00:11:23 · 100 阅读 · 0 评论 -
python-循环
# input 让程序暂停运行,等待用户输入一些文本。获取用户输入后,python 将其存储在一个变量中,以方便你使用message = input("Tell me something, and i will repeat it back to you ")print(message)name = input("please enter your name ")print('Hello ' + name + ' !')# 使用 int() 来获取数值输入age = input("plea原创 2020-12-14 00:05:11 · 132 阅读 · 0 评论 -
python-字典
# 字典是一系列键-值对。每个键都与一个值相关联,你可以使用键来访问与之相关联的值。与键相关联的可以是数字,字符串,列表乃至字典。# 字典用放在花括号 {} 中的一系列键-值对表示# 一个简单的字典alien_0 = {'colar':'green', 'points':5}print(alien_0['colar'])print(alien_0['points'])# green# 5# 添加键-值对alien_0 = {'colar':'green', 'points':5}pr原创 2020-12-13 23:37:14 · 130 阅读 · 0 评论 -
python-if语句
cars = ['audi', 'bmw', 'subaru', 'toyora']for car in cars: if car == 'bmw': print(car.upper()) else: print(car.title())# 输出结果# Audi# BMW# Subaru# Toyora# 检查是否相等car = 'bmw'print(car == 'bmw')# True# 检查是否相等时不考虑大小写car = '原创 2020-12-13 22:51:34 · 114 阅读 · 0 评论 -
python-操作列表
# 操作列表# for 循环遍历链表magcians = ['alice', 'david', 'carolina']for mag in magcians: print(mag)# 在 for 循环中执行更多的操作magcians = ['alice', 'david', 'carolina']for mag in magcians: print(mag.title() + ", that was a great trick!") print(1)# 在 for原创 2020-12-13 22:14:29 · 105 阅读 · 0 评论 -
python-列表
# 列表# python 中使用 [] 来表示列表,并用逗号来分隔其中的元素bicycles = ['trek', 'cannondale', 'redline', 'speciallized']print(bicycles)print(bicycles[0]) # 索引从 0 开始而不是从 1 开始print(bicycles[0].title())print(bicycles[-1]) # -1 返回列表的最后一个元素print(bicycles[-2]) # -2 返回列表的倒数第二个元原创 2020-12-13 21:19:08 · 94 阅读 · 0 评论 -
python-简单数据类型
# 变量和简单数据类型# 打印print("hello world")# 变量message = "helloworld"print(message)message = "hello tyustli"print(message)# 字符串name = "ada lovelace"print(name.title()) # 以首字母大写的方式显示每个单词print(name.upper()) # 全部转换为大写print(name.lower()) # 全部转换为小写原创 2020-12-13 21:01:05 · 188 阅读 · 1 评论 -
python-字符串截取
import osstr = "0123456789"print (str[0:3]) #截取第一位到第三位的字符print (str[:]) #截取字符串的全部字符print (str[6:]) #截取第七个字符到结尾print (str[:-3]) #截取从头开始到倒数第三个字符之前print (str[2]) #截取第三个字符print (str[-1]) #截取倒数第一...原创 2020-04-07 11:58:30 · 312 阅读 · 0 评论 -
python-忽略字母大小写的搜索
import reimport os# 方法 1find = re.search('tyustli', 'This is Tyustli blogs\r\n', re.IGNORECASE)if find: print ("find string\r\n")else: print ("not find string\r\n")# 方法 2s = "This is...原创 2020-03-26 19:40:39 · 2979 阅读 · 0 评论 -
python-获取路径
import osprint '***获取当前目录***'print os.getcwd()print os.path.abspath(os.path.dirname(__file__))print '***获取上级目录***'print os.path.abspath(os.path.dirname(os.path.dirname(__file__)))print os.pat...原创 2020-03-25 18:05:38 · 210 阅读 · 0 评论 -
递归--汉诺塔
定义def hanoi(n, x, y, z): if n == 1: print(x, "->", z) else: hanoi(n-1, x, z, y) print(x, "->", z) hanoi(n-1, y, x, z)调用hanoi(5, "x", "y", "z")原创 2019-10-22 12:47:51 · 135 阅读 · 0 评论 -
Python--注释
#1、这是注释1print("Hello world1")'''''''''2、这是注释2'''''''''''print("Hello world2")""""""""""3、这是注释3"""""""""print("Hello world3")原创 2019-02-22 15:23:26 · 171 阅读 · 0 评论 -
Python--内置函数进行进制转换
python内置函数实现进制转换bin()、oct()、int()、hex()1、windows+R2、输入cmd 并确定3、输入python并回车(前提是电脑安装了python环境)4、结果原创 2019-02-22 15:00:49 · 1077 阅读 · 0 评论
分享