Python学习第十天打卡带有实例

数据类型注解

# var_1: int = 10

# var_2: float = 3.1415

#

#

# # 类对象类型注解

# class Student:

# pass

#

#

# stu: Student = Student()

#

# # 基础容器类型注解

# my_list: list = [1, 2, 3]

# my_tuple: tuple = (1, 2, 3)

#

# # 容器类型详细注解

# my_set: set = {1, 2, 3}

# my_dict: dict = {"itheima": 666}

#

#

# # 需要注意的是,类型注解只是提示性的,并非决定性的,数据类型和注解类型无法对应也不会导致错误。

# # 在注释中进行类型注解:# type:类型

# ---------------------------------------------------------------------------------------------

# def greet(name: str) -> str: # greet 函数的类型注解表明它接受一个字符串参数(name: str),并且它返回一个字符串(-> str)。

# return 'Hello ' + name

#

#

# def greet(name: str) -> str: # Greet 类有一个方法 greet,该方法接受一个字符串参数 name 并返回一个字符串。

# # 注意,对于类方法,你需要添加 self 参数,它表示类实例本身。

# return 'Hello ' + name

#

#

# class Greeter:

# pass

#

#

# class Greeter:

# greeting: str = "Hello" # Greeter 类有一个类变量 greeting,它是一个字符串。

# # 然后在 greet 方法中,我们使用了 self.greeting 来引用这个类变量。

#

# def greet(self, name: str) -> str:

# return self.greeting + name

# # 多态

# class Shape:

# def draw(self):

# pass

#

#

# class Circle(Shape):

# def draw(self):

# print("Drawing a circle")

#

#

# class Square(Shape):

# def draw(self):

# print("Drawing a square")

#

#

# shapes = [Circle(), Square()]

#

# for shape in shapes:

# shape.draw()

# # Shape 类有一个 draw 方法,但它的具体实现没有定义。

# # Circle 和 Square 类都是 Shape 的子类,并且它们都有自己的 draw 方法,实现不同形状的绘制

# ----------------------------------------------------------------------------------------------------

# 抽象基类(Abstract Base Class,简称 ABC)

 

# from abc import ABC, abstractmethod

#

#

# # abstractmethod是定义抽象方法的一种方式,通常与abc模块(Abstract Base Classes)一起使用。

#

# class Shape(ABC):

# @abstractmethod

# def draw(self):

# pass

#

#

# class Circle(Shape):

# def draw(self):

# print("Drawing a circle")

#

#

# class Square(Shape):

# def draw(self):

# print("Drawing a square")

#

#

# shapes = [Circle(), Square()]

#

# for shape in shapes:

# shape.draw()

# x = y**2-z**2 x要么是四的倍数要么是奇数

# def panduan(x):

# if x % 4 == 0:

# return 1

# elif x % 2 != 0:

# return 1

# else:

# return 0

#

#

# L, R = map(int, input().strip().split())

# count = 0

# for e in range(L, R+1):

# if panduan(e) == 1:

# count += 1

# print(count)

 

# ---------------------------------------------------------------------------------------------------

 

# import random

#

#

# def select_num():

# l = list(range(1, 37))

# nums = random.sample(l, 7)

# print(type(l))

# return nums

#

#

# num = select_num()

# for e in num:

# print(e, "", end='')

 

# ------------------------------------------------------------------------------------------------------------

 

# import numpy as np

# import itertools

#

# # n = [[1, 2, 3, 4], [5, 6, 7, 8]]

# # m = np.array(n) # 将嵌套列表转化成二维数组

# # print(m)

# j = np.zeros((1, 1), dtype=int, order='C') # shape形状几行几列,dtype数据类型,order可选项

# print(j)

# o = np.ones((1, 1), dtype=int, order='C')

# print(o)

# # p = np.array([4, 5, 6])

# i = np.ones(shape=(3, 3), dtype=[('x', 'int'), ('y', 'float')], order='C')

# print(i)

# h = np.arange(5, 9, 1) # 产生步长为1从5到9不含9

# print(h)

# # k = np.hstack(o, j)

# # print(k)

# import numpy as np

# i = [0,1, 2, 3, 4, 5, 6, 7, 8, 9]

# m = np.array(i)

# print(type(m))

# r = np.reshape(i, (5, 2))

# print(r)

# dp = [[[0] for _ in range(5)]for y in range(5)] # 二维数组也是嵌套列表

# print(dp)

# ---------------------------------------------------------------------------------------

 

# import numpy as np

#

# # 创建两个一维数组

# a = np.array([1, 2, 3]) # numpy里面的元素要一致和python普通数组不同

# b = np.array([4, 5, 6])

#

# # 使用hstack将这两个数组合并

# c = np.hstack((a, b))

# print(type(c))

# print(c) # 输出:[1 2 3 4 5 6]

# -----------------------------------------------------------------------------------

# 给定一个正整数k(3≤k≤15),把所有k的方幂及所有有限个互不相等的k的方幂之和构成一个递增的序列

# k, n = map(int, input().split())

# a = [1, k]

# b = 2

# while True:

# c = a.index(a[-1])

#

# for i in range(0, c):

# e = a[c] + a[i]

# a.append(e)

# a.append(k ** (b))

# b += 1

# if len(a) >= n:

# break

# a.sort() # 不明白是否是递增数列的话就排下序

# print(a[n - 1])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值