python小白之旅——python能用来做什么

1.为什么

为什么要使用python而不是其他开发语言(java/c)

软件质量
提高开发者效率
程序的可移植性
标准库的支持
组件集成
享受乐趣

2.是什么

python是面向对象的脚本语言

3.谁在使用

4.能做什么

# -*- coding: utf-8 -*-

import os


def file_name(file_dir):
    for root, dirs, files in os.walk(file_dir):
        print(root)  # 当前目录路径
        print(dirs)  # 当前路径下所有子目录
        print(files)  # 当前路径下所有非目录子文件


file_name("D:\安装包")

参考:https://blog.csdn.net/lsq2902101015/article/details/51305825

参考:https://blog.csdn.net/u013255127/article/details/51733177

做网站:https://www.cnblogs.com/EmptyFS/p/7726030.html

高级计算器

import numpy as np

a = np.array([30,40,50,60])
b = np.arange(4)

print(a)
print(b)
print("\na-b:")
#俩个数据相减
c = a - b
print(c)
print("\nb**2:")
#b数组二次方
print(b**2)
#比较
print("\na<45:")
print(a<45)

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import pygame
from pygame.locals import *
from sys import exit

background_image = 'image/sushiplate.jpg'
mouse_image = 'image/fugu.png'

# 初始化pygame,为使用硬件做准备
pygame.init()
# 创建了一个窗口
screen = pygame.display.set_mode((640, 480), 0, 32)
# 设置窗口标题
pygame.display.set_caption("hello world")

# 加载并转换图像
background = pygame.image.load(background_image).convert()
mouse_cursor = pygame.image.load(mouse_image).convert_alpha()

while True:
    for event in pygame.event.get():
        if event.type == QUIT:  # 接收到退出事件后退出程序
            exit()
    screen.blit(background, (0, 0))  # 画上背景图

    x, y = pygame.mouse.get_pos()  # 获得鼠标位置
    # 计算光标左上角位置
    x -= mouse_cursor.get_width()/2
    y -= mouse_cursor.get_height()/2
    # 画上光标
    screen.blit(mouse_cursor, (x, y))

    # 刷新画面
    pygame.display.update()

参考:https://blog.csdn.net/fengf2017/article/details/79300801

注意:alt+enter 可以快捷添加依赖包(鼠标悬停在开头的import 的红色错误上)

猜你喜欢

转载自blog.csdn.net/u014112608/article/details/82556937